Programmatically find out if UAC is turned ON
by
, 15-Aug-2010 at 03:14 AM (10607 Views)
UAC, short for User Access Control, the feature built in Microsoft Windows Vista and higher is turned off by a number of users and developers because they do not like that the operating system asks for permission to write or access certain areas of their environment. Building your applications you are however advised not to do this because sooner or later you will install your not UAC compliant application at a UAC controlled PC and that is not goo.
How can you find out if UAC is enabled or disabled? With a bit of googling I found out that the value is stored in the registry under:
With this knowledge I was able to write the following test routine.Code:SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
To complete the test I wrote the following code that shows how you call above routine:Code:Class cUACTester Is A cObject Function IsUACOn Returns Boolean Handle hoRegistry String sKey Boolean bKeyExists bKeyOpened bValueExists bUACOn DWord dwValue If (SysConf (SYSCONF_OS_MAJOR_REV) >= 6 and SysConf (SYSCONF_OS_MINOR_REV) >= 0) Begin Get Create (RefClass (cRegistry)) to hoRegistry Set pfAccessRights of hoRegistry to KEY_READ Set phRootKey of hoRegistry to HKEY_LOCAL_MACHINE Move "SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" to sKey Get KeyExists of hoRegistry sKey to bKeyExists If (bKeyExists) Begin Get OpenKey of hoRegistry sKey to bKeyOpened If (bKeyOpened) Begin Get ValueExists of hoRegistry "EnableLUA" to bValueExists If (bValueExists) Begin Get ReadDword of hoRegistry "EnableLUA" to dwValue Move (dwValue = 1) to bUACOn End Send CloseKey of hoRegistry End End Send Destroy of hoRegistry End Function_Return bUACOn End_Function End_Class
Code:Procedure TestUACOnOff Global Handle hoUACTester Boolean bIsOn Get Create (RefClass (cUACTester)) to hoUACTester Get IsUACOn of hoUACTester to bIsOn If (not (bIsOn)) Begin Send Stop_Box "TSSSK, you turned off UAC, we will now notify Microsoft about your misbehavior..." End Else Begin Send Info_Box "To all: We have found a true Microsoft believer!" End Send Destroy of hoUACTester End_Procedure Send TestUACOnOff