Jump to content

UDF: _UserAccountContol_SetLevel.au3


Carlo84
 Share

Recommended Posts

I could not find a User account script on these forums that was satisfactory, a On/Off setting is quite useless if it cant be configured, so i wrote this up.
Should work on both x64 and x86 compiled scripts. Windows7 and Vista.

Functions:

_UAC_SetLevel


Example:

#include "_UserAccountContol_SetLevel.au3"
_UAC_SetLevel(0) ;Never notify
_UAC_SetLevel(1) ;Notify on apps only (no dim)
_UAC_SetLevel(2) ;Notify on apps only
_UAC_SetLevel(3) ;Notify on apps and user



Script:

#include-once
#Region _UAC_SetLevel
; #FUNCTION# ;===============================================================================
;
; Name...........: _UAC_SetLevel
; Description ...: Sets the level of "User Account Control".
; Syntax.........: _UAC_SetLevel($iLevel)
; Parameters ....: $iLevel - The level to set UAC to.
;                  |0 =  Never notify
;                  |1 = Notify on apps only (no dim)
;                  |2 = Notify on apps only
;                  |3 = Notify on apps and user
; Return values .: Success - Returns 1
;                 Failure - Returns 0
;
; Author ........: Carlo Westmaas
; Modified.......:
; Remarks .......: Changes only take effect after a reboot.
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/topic/139626-udf-useraccountcontol-setlevelau3/
; Example .......; No
;
; ;==========================================================================================
Func _UAC_SetLevel($iLevel)
    If $iLevel < 0 Or $iLevel > 3 Then Return SetError(1, 0, 0)
    If @OSVersion <> "WIN_VISTA" And @OSVersion <> "WIN_7" Then Return SetError(2, 0, 0)
    Local $sKey = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System', $a[3], $aValue[3] = ['EnableLUA', 'ConsentPromptBehaviorAdmin', 'PromptOnSecureDesktop'], $iError = 0
    If @OSArch = 'X64' And @AutoItX64 <> 1 Then $sKey = 'HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
    If $iLevel = 0 Then Dim $a[3] = [0, 0, 0] ;Never notify
    If $iLevel = 1 Then Dim $a[3] = [1, 5, 0] ;Notify on apps only (no dim)
    If $iLevel = 2 Then Dim $a[3] = [1, 5, 1] ;Notify on apps only
    If $iLevel = 3 Then Dim $a[3] = [1, 2, 1] ;Notify on apps and user
    For $i = 0 To 2
        $iError += RegWrite($sKey, $aValue[$i], 'REG_DWORD', $a[$i])
    Next
    If $iError <> 3 Then Return SetError(3, 0, 0)
    Return 1
EndFunc   ;==>_UAC_SetLevel
#EndRegion _UAC_SetLevel

Edited by Carlo84
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...