Jump to content

_Reg_UAC


James
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • 1 month later...

What's wrong with System Configuration Utility (msconfig.exe)? I see no reason for the frequent use of activate/deactivate UAC. Moreover it will work only after reboot your system.

Edited by Yashied
Link to comment
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

Link to comment
Share on other sites

  • 7 months later...

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

Link to comment
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.
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...