locked
How to get system UAC(LUA) status when using built-in administrator account login system RRS feed

  • Question

  • Our application want to get current system UAC status,and to do different action according it.
    We can got right UAC status using below code When normal account login system.
    We always got TokenElevationTypeDefault result if we use built-in administrator account login system.
    whether we set UAC on or off before reboot system.

     

    Key code:
    if ( OpenProcessToken( ::GetCurrentProcess(), TOKEN_QUERY, &hToken ) )
      {
       DWORD dwLength = 0;
       TOKEN_ELEVATION_TYPE tet;
       GetTokenInformation( hToken, TokenElevationType, &tet, sizeof(tet), &dwLength);
       // Here, tet always returns TokenElevationTypeDefault in built-in account when UAC on or not.
    }

     

    BTW:
    KLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies \System\EnableLUA only can get curent  setting UAC(LUA) status, not current system status.

     

    Any suggestion or advice is wellcome,thanks.

     

    -opqit

    Thursday, April 10, 2008 3:08 PM

Answers

  • The Windows Vista guidelines recommend that you do not change your application behaviour dependent upon the state of UAC or a user's permission levels. That said, if you need to do this there is some sample code here.

     

    Thursday, April 10, 2008 3:51 PM

All replies

  • The Windows Vista guidelines recommend that you do not change your application behaviour dependent upon the state of UAC or a user's permission levels. That said, if you need to do this there is some sample code here.

     

    Thursday, April 10, 2008 3:51 PM
  •  

    AndyCadley,thanks for you reply.

     

    Actually, I had done the VistaTool'ss work before this thread.

    Unfortunately, we cannot get right UAC(LUA)  status using these methods.

     

    Built-in administrator accoutn and UAC off

    GetElevationType returns  TokenElevationTypeDefault

    IsElevated             returns  TRUE

     

    Built-in administrator account and UAC ON

    GetElevationType returns  TokenElevationTypeDefault

    IsElevated             returns  TRUE

     

    So we cannot get right account status when using built-in administrator account login system.

     

    Is there any aother method to separate above case?

     

    BTW:

    If you using TokenMandatoryPolicy to check it, we still get the same value 3 in above two case.

     

    Thanks,

    -opqit

    Friday, April 11, 2008 1:46 AM
  •  

    Anyone can provide any suggestion?
    Wednesday, April 16, 2008 2:09 AM
  • Hi – I think my information can help:

    That question is a wrong question to ask! Take a moment and ask yourself, do you really need to check the User Account Control (UAC) settings?

    The answer is: No, you do not need to manually check the UAC status. Since, Microsoft has developed the system, as follow: As soon as UAC is turned ON, the user executing a program, will not have problem, until she/he wants to write to the “root” – and they do not have administrator permission, what will happen is the following:

    A “UnauthorizedAccessException” or "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" will be thrown telling the user that she/he does not have permission to access the system root directory on the disk.  

    By adding try-and-catch statements like this:

    Try
    {}
    catch(UnauthorizedAccessException ex){
           MessageBox.show(ex.Message.ToString(), “Access Denied!”);
    }

    The UAC technology is built-in inside the Windows Vista Kernel.

    I hope the above information helps…

    Have a nice day…

    Best regards,
    Fisnik


    Coder24.com
    • Proposed as answer by Fisnik Hasani Wednesday, October 21, 2009 6:25 PM
    Sunday, October 11, 2009 4:37 PM
  • Hello opqit:

    How is the situation on your side?
    Is this thread solved or NOT?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Wednesday, October 21, 2009 6:25 PM