none
How tell if UAC is on/off?

    Question

  • Is there a function to find out if UAC is on or off?  I just want to display a dialog telling the user he can't do what he wants to do while UAC is on.
    Wednesday, March 19, 2008 9:50 PM

Answers

  • This question is almost universally the wrong one to ask, because you really want to be asking something else - usually, 'do I have administrative privileges'.

     

    If you don't need admin privileges, because your app is tested for the standard user like it most likely should be, then you don't have a reason to care if UAC is on or not.  Your app should then be manifested with a requestedExecutionLevel of 'asInvoker'.

     

     

    If your app does things that require admin privileges to work:

    If it only sometimes needs them in order to perform an uncommon action: seperate out the things that require a fully privileged administrator to work, look on MSDN for a sample called 'CoCreateInstanceAsAdmin' for a pattern on how to package those into a COM object that you can create as a full administrator.  Manifest the rest of the app with a requestedExecutionLevel of 'asInvoker'. If you do this right, you don't care if UAC is on or off.

     

    If your app is completely unable to work without being run elevated in entirety, or is just never something appropriate for a regular user or a non-elevated administrator to do, set a requestedExecutionLevel of requireAdministrator on the applications embedded manifest.  In this case, you don't care if UAC is on or off, either.

     

    Otherwise:

    If you are just porting an app from XP to Vista, and you never tested the XP version as a regular user, but think that in theory it probably should work: take the time to test and redesign your application as necessary.  Windows is a multi-user operating system, and not every user will be an administrator.

    Wednesday, March 19, 2008 10:35 PM

All replies

  • This question is almost universally the wrong one to ask, because you really want to be asking something else - usually, 'do I have administrative privileges'.

     

    If you don't need admin privileges, because your app is tested for the standard user like it most likely should be, then you don't have a reason to care if UAC is on or not.  Your app should then be manifested with a requestedExecutionLevel of 'asInvoker'.

     

     

    If your app does things that require admin privileges to work:

    If it only sometimes needs them in order to perform an uncommon action: seperate out the things that require a fully privileged administrator to work, look on MSDN for a sample called 'CoCreateInstanceAsAdmin' for a pattern on how to package those into a COM object that you can create as a full administrator.  Manifest the rest of the app with a requestedExecutionLevel of 'asInvoker'. If you do this right, you don't care if UAC is on or off.

     

    If your app is completely unable to work without being run elevated in entirety, or is just never something appropriate for a regular user or a non-elevated administrator to do, set a requestedExecutionLevel of requireAdministrator on the applications embedded manifest.  In this case, you don't care if UAC is on or off, either.

     

    Otherwise:

    If you are just porting an app from XP to Vista, and you never tested the XP version as a regular user, but think that in theory it probably should work: take the time to test and redesign your application as necessary.  Windows is a multi-user operating system, and not every user will be an administrator.

    Wednesday, March 19, 2008 10:35 PM
  • I predicted this was going to happen.  I know what I'm doing.  I just want to know if UAC is on or off.  Can I find that out or not?

    Thursday, March 20, 2008 12:10 AM
  • You can check on the current value of the /policy/, but that won't tell you accurately if UAC is on or off.
    Thursday, March 20, 2008 2:13 AM
  • Is there a function to find out if UAC is on or off?  I just want to display a dialog telling the user he can't do what he wants to do while UAC is on.

    Hi – Dick Monahan:

    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 Friday, October 09, 2009 7:49 PM
    Saturday, October 03, 2009 8:04 AM
  • Hello Dick:

    Is this issue solved? How is the situation on your side?
    Please provide some information, thanks!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Friday, October 09, 2009 7:48 PM
  • Hello Dick:

    Is this issue solved? How is the situation on your side?
    Please provide some information, thanks!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Friday, October 23, 2009 7:59 PM
  • What Microsoft does is hilarious. if i want to know if the UAC is on/off you are telling me that Idon't neet to manually check the UAC stauts? What i want to know is if there is a CMD that after is run could give me a status of this UAC. I need this for different reasons, and it's very odd that you're telling me that i don't have to know this.

     

    Tuesday, August 02, 2011 7:08 AM