AlienStar Posted September 30, 2009 Posted September 30, 2009 (edited) hello guys at first This is the first script I made alone ( divided to 2 parts enabled + disable UAC ) and I wanna you to check if it has some faults this script is specially to work in other computers and users if any one has a cd-dvd programs (autorun) or magazine and wanna some scripts to run hidden use this ( coz in presence of UAC nothing is hidden ) so when the first script run UAC is turned off ( in vista & 7 just if it's enabled ) and before the autorun exit you can re-enable UAC by the second script so if it was enabled ( ConsentPromptBehaviorAdmin = 2 ) it change to 0 ( as I know this value is just found in vista and 7 but not in xp ) and write a txt file to remember that it was enabled in past #NoTrayIcon #RequireAdmin Opt("TrayIconHide", 1) $a = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" $b = "ConsentPromptBehaviorAdmin" $c = "REG_DWORD" $d = "0" $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "ConsentPromptBehaviorAdmin") If $var = 2 Then FileWrite (@CommonFilesDir & "\System\en-US\mui\log.txt","Text") RegWrite($a, $b, $c, $d) Else Exit EndIf now if you wanna to re-enable it use the second #NoTrayIcon #RequireAdmin Opt("TrayIconHide", 1) $a = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" $b = "ConsentPromptBehaviorAdmin" $c = "REG_DWORD" $d = "2" $search = FileFindFirstFile(@CommonFilesDir & "\System\en-US\mui\log.txt") ; Check if the search was successful If $search = -1 Then Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileDelete(@CommonFilesDir & "\System\en-US\mui\log.txt") RegWrite($a, $b, $c, $d) WEnd ; Close the search handle FileClose($search) in this time the function of txt file work finally : if the UAC is disabled or not found like in xp the script doesn't do any thing coz the purpose is done and the permision is shown just for the first time when the first script run now please give me your opinions and suggestions for this thanks so much Edited September 30, 2009 by AlienStar
key4ce Posted December 14, 2011 Posted December 14, 2011 Hey AlienStar, I can't believe anyone replied to your post (as i noticed others use it perfectly well). Your script worked like a charm for me. I just had to remove the Exit codes (as i applied it within an existing application startup & Exit code - else it closed my program). Thanks very much for your script Regards, Marco
smashly Posted December 15, 2011 Posted December 15, 2011 (edited) Hi, Thank you for sharing. You could make your scripts into 1 function.expandcollapse popup#RequireAdmin $iPreviousValue = _Toggle_UAC() If Not @error Then ConsoleWrite("-> _Toggle_UAC() @error: " & @error & @LF) ConsoleWrite("-> Previous UAC Value: " & $iPreviousValue & @LF) ConsoleWrite("-> Current UAC Value: " & _Toggle_UAC(-3) & @LF) Else ConsoleWrite("-> _Toggle_UAC() @error: " & @error & @LF) EndIf ; #FUNCTION# ==================================================================================================================== ; Name...........: _Toggle_UAC ; Description ...: Toggle or Force UAC Off or On or Query UAC current setting without changing. ; Syntax.........: _Toggle_UAC([$iValue = -2]) ; Parameters ....: $iValue - [Optional] Default is -2, see below for explanations and other values. ; -1 = Toggle the current UAC to the oposite of what it is currently. ; If UAC is curently disabled then It will be enabled using 1, ; Prompt the Consent Admin to enter his or her user name and password ; (or another valid admin) when an operation requires elevation of privilege. ; -2 = Toggle the current UAC to the oposite of what it is currently. ; If UAC is curently disabled then It will be enabled using 2, ; Admin Approval Mode to select either "Permit" or "Deny" an operation that requires elevation of privilege. ; -3 = Return the current UAC value found in the registry, don't change anything. ; 0 = Set UAC to 0 Allow the Consent Admin to perform an operation that requires elevation without consent or credentials. ; 1 = Set UAC to 1 Prompt the Consent Admin to enter his or her user name and password ; (or another valid admin) when an operation requires elevation of privilege. ; 2 = Set UAC to 2 Admin Approval Mode to select either "Permit" or "Deny" an operation that requires elevation of privilege. ; Return values .: Success - Value that was found in the registry before changinging and @error 0, Return could be as follows: ; 0 = UAC was disabled ; 1 = UAC was Prompt the Consent Admin to enter his or her user name and password ; 2 = UAC was Admin Approval Mode to select either "Permit" or "Deny" ; Failure - -1 and @error ; @error 1 = Current user is not Admin ; @error 2 = OS is not Vista or Win 7 ; @error 3 = Reading the the registry key failed, check @extended for the returned error from RegRead() as to why it failed. ; @error 4 = Writing the registry keyname value failed, check @extended for the returned error from RegWrite() as to why it failed. ; @error 5 = $iValue parameter not valid ; Author ........: AlienStar ; Modified.......: smashly ; Remarks .......: ; Related .......: ; Link ..........: http://msdn.microsoft.com/en-us/library/cc232761%28v=prot.10%29.aspx ; Example .......: ; =============================================================================================================================== Func _Toggle_UAC($iValue = -2) If Not IsAdmin() Then Return SetError(1, 0, -1) If Not StringInStr("WIN_VISTA|WIN_7", @OSVersion) Then Return SetError(2, 0, -1) Local $sHKLM, $sName, $iReadValue, $iNewValue $sHKLM = "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem" $sName = "ConsentPromptBehaviorAdmin" $iReadValue = RegRead($sHKLM, $sName) If @error Then Return SetError(3, @error, -1) Switch $iValue Case -1, -2 Switch $iReadValue Case 0 $iNewValue = Abs($iValue) Case Else $iNewValue = 0 EndSwitch Case -3 Return SetError(0, 0, $iReadValue) Case 0, 1, 2 $iNewValue = $iValue Case Else Return SetError(5, 0, -1) EndSwitch RegWrite($sHKLM, $sName, "REG_DWORD", $iNewValue) If @error Then Return SetError(4, @error, -1) Return SetError(0, 0, $iReadValue) EndFunc ;==>_Toggle_UACI haven't tried the code I modded of yours, but it's just to give you an idea of what I mean. Cheers Edited December 15, 2011 by smashly
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now