Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect whether Vista UAC is enabled?

Tags:

I need my application to behave differently depending on whether Vista UAC is enabled or not. How can my application detect the state of UAC on the user's computer?

like image 793
Andrei Belogortseff Avatar asked Sep 18 '08 18:09

Andrei Belogortseff


People also ask

How do I know if UAC is enabled?

to see if UAC is enabled to the start menu and click the control panel. From there click User Accounts. You will see an option 'Turn User Account Control on or off' - click that and you will then see a checkbox to enable UAC. Under Security Settings choose Local Policies and then Security Options.

What is Windows UAC status?

The Windows UAC Status service monitors if the UAC is enabled on the target machine.


2 Answers

This registry key should tell you:

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System 

Value EnableLUA (DWORD)

1 enabled / 0 or missing disabled

But that assumes you have the rights to read it.

Programmatically you can try to read the user's token and guess if it's an admin running with UAC enabled (see here). Not foolproof, but it may work.

The issue here is more of a "why do you need to know" - it has bearing on the answer. Really, there is no API because from a OS behavior point of view, what matters is if the user is an administrator or not - how they choose to protect themselves as admin is their problem.

like image 66
Philip Rieck Avatar answered Oct 17 '22 21:10

Philip Rieck


This post has sample code in C# to test if UAC is on and if the current app has been given elevated rights. You can download the code and interpret as needed. Also linked there is a sample that shows the same in C++

http://www.itwriting.com/blog/198-c-code-to-detect-uac-elevation-on-vista.html

The code in that post does not just read from the registry. If UAC is enabled, chances are you may not have rights to read that from the registry.

like image 23
Ryan Farley Avatar answered Oct 17 '22 21:10

Ryan Farley