Sign in to follow this  
Followers 0
James

_Reg_UAC

9 posts in this topic

#1 ·  Posted (edited)

Little function I wrote. It changes the registry key for Windows Vista UAC.

; #FUNCTION# ====================================================================================================


================
; Name...........: _Reg_UAC
; Description ...: Changes the UAC setting on or off
; Syntax.........: _Reg_UAC($ioSwitch = 1)
; Parameters ....: $ioSwitch - Turns on/off UAC, valid values:
;               |0 - Off
;               |1 - On
; Return values .: Success      - 1
;               Failure:
;                       Not Vista   3
;                       Off switch and registry match   1
;                       On switch and registry match    2
; Author ........: James Brooks (JamesBrooks)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; Yes
; ====================================================================================================


===========================

Func _Reg_UAC($ioSwitch = 1)
    Local $strReg = "HKLM64\Software\Microsoft\Windows\CurrentVersion\Policies\System"
    Local $strKey = "EnableLUA"
    If @OSVersion = "WIN_VISTA" Then
    ; Check if the key matches off
        If RegRead($strReg, $strKey) = 0 Then
            If $ioSwitch = 0 Then
                Return SetError(1); Error reg and switch are equal - off
            EndIf
        ElseIf RegRead($strReg, $strKey) = 1 Then
            If $ioSwitch = 1 Then
                Return SetError(2); Error reg and switch are equal - on
            EndIf
        Else
            RegWrite($strReg, $strKey, "REG_DWORD", $ioSwitch)
            Return 1; Good return
        EndIf
    Else
        Return SetError(3); Not Vista
    EndIf
EndFunc ;==>_Reg_UAC

Pretty bad but can be useful. I don't use SetError() much so it's probably wrong :P

Edited by JamesBrooks

Share this post


Link to post
Share on other sites



Thank you it works good ^_^


[font="Comic Sans MS"][size="4"]My UDF's:[/size]1. _ChooseIconAnd this is just the beginning[/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Share this post


Link to post
Share on other sites

I think the only think wrong with it that I can see is that it returns 0 and ets Error to 1/2 when It's not changing the value.

I would change it to this...

If $ioSwitch = 1 Then
    Return SetError(2, 0, 1); Error reg and switch are equal - on
EndIf

or maybe:

If $ioSwitch = 1 Then
    Return SetError(0, 2, 1); Error reg and switch are equal - on
EndIf

as then It won't set off alarm bells when the values are equal.

Don't know if thats what you wan't, but it makes sense as if you tell it to set the key to 2, even if it doesn't do anything, if the key ends up 2 then it should be OK.

Other than that, I think this should be run by anyone on vista... saves everyone some trouble.

MDiesel

Share this post


Link to post
Share on other sites

...

Other than that, I think this should be run by anyone on vista... saves everyone some trouble.

MDiesel

I don't get it. How?

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Hello

How can check, if UAC is Active ?

like require the state of UAC. maybe can check, running service, registry, or dll call.

Yashied you are right.

the regkey: $strReg = "HKLM64\Software\Microsoft\Windows\CurrentVersion\Policies\System"

the settings are activ after reebot.

regards

lite

Share this post


Link to post
Share on other sites

Hello

How can check, if UAC is Active ?

like require the state of UAC. maybe can check, running service, registry, or dll call.

Yashied you are right.

the regkey: $strReg = "HKLM64\Software\Microsoft\Windows\CurrentVersion\Policies\System"

the settings are activ after reebot.

regards

lite

If I remember correctly, there is a key (I think GeoSoft noted this), that doesn't require a reboot.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

If I remember correctly, there is a key (I think GeoSoft noted this), that doesn't require a reboot.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $strReg = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"

$frmMain = GUICreate("UAC Control", 187, 50)
$btnOn = GUICtrlCreateButton("Turn UAC On", 8, 8, 83, 33, 0)
$btnOff = GUICtrlCreateButton("Turn UAC Off", 96, 8, 81, 33, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnOn
            _Reg_UAC()
        Case $btnOff
            _Reg_UAC(0)
    EndSwitch
WEnd

; 1 = Default
; 0 = Off
Func _Reg_UAC($ioSwitch = 1)
    Local $strKey = "ConsentPromptBehaviorAdmin"
    If @OSVersion = "WIN_VISTA" Then
        ; Check if the key matches off
        If RegRead($strReg, $strKey) = 0 Then
            If $ioSwitch = 0 Then
                Return SetError(0) ; Error reg and switch are equal - off
            EndIf
        ElseIf RegRead($strReg, $strKey) = 1 Then
            If $ioSwitch = 1 Then
                Return SetError(2) ; Error reg and switch are equal - on
            EndIf
        Else
            RegWrite($strReg, $strKey, "REG_DWORD", $ioSwitch)
            Return 1 ; Good return
        EndIf
    Else
        Return SetError(3) ; Not Vista
    EndIf
EndFunc   ;==>_Reg_UAC

That should not require a reboot on Windows Vista.

Edited by JamesBrooks

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0