Jump to content
Sign in to follow this  

UDF: _UserAccountContol_SetLevel.au3

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.




#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


#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])
    If $iError <> 3 Then Return SetError(3, 0, 0)
    Return 1
EndFunc   ;==>_UAC_SetLevel
#EndRegion _UAC_SetLevel

Edited by Carlo84

Share this post

Link to post
Share on other sites

Thanks for this great UDF! Love it! Works perfectly!

Edit: Fixed issue. Had nothing to do with the UDF.

Edited by intime69

Developer and Co-OwnerInTime Applicaitons Inc.

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  

  • Similar Content

    • Jefrey
      By Jefrey
      Needed a way to store global temporary & permanent information and came up with this.
      This is inspired by NodeJS's store and store2 packages, as well as W3 specs' localStorage and sessionStorage, offering multiple ways of usage.
      This is not related to any browser's storage, nor will allow you to access or modify browsers storage - although this is possible and not a hard task, this is not what this UDF is intended to do.
      This UDF offers functions for temporary storage (that gets cleaned up once the application is shutdown) that is kept on memory using ScriptingDictionary, as well as for permanent storage, that is saved on the harddisk as an encrypted file.
      sessionStorage (temporary storage)
      It's useful to keep application state and temporary settings accessible by any part of your script (although it could also be done with a global variable, I still prefer this method).
      You have multiple ways, at your choice, to:
      ; add or modify a key sessionStorage("foo", "bar") store("foo", "bar") sessionStorage_set("foo", "bar") sessionStorage_setItem("foo", "bar") ; read a key (returns false if key does not exist) $read = sessionStorage("foo") $read = store("foo") $read = sessionStorage_get("foo") $read = sessionStorage_getItem("foo") ; delete a key sessionStorage_remove("foo") ; delete all keys sessionStorage_clear() sessionStorage_clearAll() localStorage (permanent storage)
      It's useful to store user-defined settings.
      ; initialize ; this is optional, but allows you to control ; how things are going to be saved localStorage_startup([file where you want the settings to be saved], [crypt password]) ; by default, if not supplied, if supplied the "Default" keyword (or if you dont initialize), ; the file will be a random-named file (based on @ScriptFullPath) at user's %APPDATA% ; and the password will also be based on @ScriptFullPath ; you can set only the crypt password if you want: ; localStorage_startup(Default, "mypassword") ; the usage is the same as sessionStorage ; add or modify a key localStorage("foo", "bar") store2("foo", "bar") ; notice the '2' localStorage_set("foo", "bar") localStorage_setItem("foo", "bar") ; read a key (returns false if key does not exist) $read = localStorage("foo") $read = store2("foo") $read = localStorage_get("foo") $read = localStorage_getItem("foo") ; delete a key localStorage_remove("foo") ; delete all keys localStorage_clear() localStorage_clearAll() Download
    • griefman
      By griefman
      Hi everyone,
      i am writing to you after a very long struggle i had while trying to figure out how to send a simple click inside a virtual machine running in vmware workstation 14.
      i have an autoit script running on my host machine watching for the UAC prompt to be displayed in a running vm. Both the host and the guest OS are Windows 10. This script worked perfectly with virtual box. It recognized the UAC prompt and clicked inside and the UAC was accepted. Since i switched to VMware Workstation 14, the script no longer clicks inside the VM successfully. It acts as if it clicks, but it doesn't. 
      I tried sending key combinations instead of a click, so that the VM can grab the input, but it also did not work. Every attempt that i made to send clicks or keys from the host inside the VM did not work. I tried using:
      I also noticed that while the cursor moves to the target which has to be cilcked when my vmware worstation window is not focused, it even doesn't do that when i WinActivate the vmware workstation window first.
      Did anyone experience such an issue, or maybe could give me a hint, what else i could use to send a key combination or a mouse click in a vmware workstation 14 pro guest window?
      here is my code, which works with virtualbox:
      #AutoIt3Wrapper_Icon=".\uac.ico" #include <ImageSearchSubrogated.au3> FileInstall(".\ImageSearchDLL.dll", ".\ImageSearchDLL.dll", 0) FileInstall(".\UAC_ginloSetup.bmp", ".\UAC_ginloSetup.bmp", 0) FileInstall(".\UAC_Yes.bmp", ".\UAC_Yes.bmp", 0) ; set global variables for the coordinates, which should be delivered global $x1 = 0, $y1 = 0 global $x2 = 0, $y2 = 0 global $counter1 = 0 global $counter2 = 0 global $sleep = 10000 global $smallSleep = 5000 ; execute the script in a loop, so that it will hopefully recover from some unexpected errors While $counter1 < 1 checkForImage() WEnd #cs ------------ Functions #ce ------------ Func checkForImage() While $counter2 < 1 ; search for the UAC in the entire screen - 2 screens supported local $searchUac = _ImageSearchArea('UAC_ginloSetup.bmp', 1, -2568, -8, 5136, 1440, $x1, $y1, 0) If $searchUac = 1 Then ; if the UAC was found search for the Yes button in a an area 200 x 200 from the middle of the found UAC image local $searchYes = _ImageSearchArea('UAC_Yes.bmp', 1, $x1, $y1, $x1 + 200, $y1 + 200, $x2, $y2, 0) If $searchYes = 1 Then ; if the Yes button was found click it and pause the script for $sleep seconds MouseClick("left", $x2, $y2, 1,0) Sleep($sleep) Else ; if the Yes button was not found retry from the beginning in $smallSleep seconds MsgBox(0, "UAC found error", "UAC was found but the 'Yes' button was not found. Script will retry in " & $smallSleep & " seconds.", $smallSleep) EndIf ; another way to accept the UAC - via shortcut ;Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}") ;Send("!y") Else ; if UAC was not found try again in $sleep seconds Sleep($sleep) EndIf WEnd ; if some error occured which expired the loop, pause the script for $sleep seconds MsgBox(0, "Error", "Some Error expired the timer and the script could not recover. The script will restart in " & $sleep & " seconds.", $sleep) EndFunc  
    • tcurran
      By tcurran
      Here's a short UDF that will, at least in most cases, detect whether a window can be copied from or pasted to programmatically--for example, by Send()ing ctl-c, ctl-v. This is often disabled when programs (like your AutoIt script) run at a lower UAC integrity level than the application they are trying to operate on.
      #include <WinAPI.au3> Func _WindowIsPasteable($handle) ;accepts window handle; returns true or false whether a window will accept Ctl-C, Ctl-V Local $bCanPaste = True Local $hTestWindowPID = 0 Local $hTestWindowTID = _WinAPI_GetWindowThreadProcessId($handle, $hTestWindowPID) _WinAPI_AttachThreadInput(_WinAPI_GetCurrentThreadId(), $hTestWindowTID, True);attach to window we want to paste into $bCanPaste = _WinAPI_GetFocus() ;Test whether window is paste-able--returns False if it is not _WinAPI_AttachThreadInput(_WinAPI_GetCurrentThreadId, $hTestWindowTID, False);detach from window thread Return $bCanPaste EndFunc Pass it a window handle; it returns true or false whether a window will accept programmatic pasting. The function may not work on the CMD window, since it handles the clipboard uniquely.
      This function works by attaching to the program thread of the window whose handle it receives, then attempting to perform a GetFocus on that thread. In most cases, the attempt will fail if the window will not accept programmatic copy-paste.
    • billshu
      By billshu
      Is there any way to change chrome settings from Auto-it.  I would like to change back and forth, between "Allow Site to show POP-ups" and "Do not Allow Site to show POP-up"?
    • irishsurfer22
      By irishsurfer22
      I'm trying to automate the process of configuring the three McAfee settings seen in the image I've attached (Host IPS, Network IPS and Firewall).  Clicking one of them toggles the setting and closes the menu.  I want them all OFF.  This script will be used on different computers so the settings might be have different initial setups.
      This is my first time using AutoIt and I have very limited coding experience--mostly MATLAB.  Please excuse any lack of knowledge or terminology. 
      So far my code is able to
      1. Find the visible McAfee icon in the system tray. 
      2. Click the icon.
      3. Send "Q" to open up the Quick Settings menu.
      4. Toggle settings blindly using keystrokes.
      The problem I'm having is I don't know how to "read" the status of the setting before toggling it.  This means I might be switching it from Off to On by mistake,
      when I should really just leave it alone. 
      I'm wondering a couple of things. 
      1. Is there an easy way to "read" the status of the setting?  This would solve the problem.  Part of the challenge with this overall assignment is that there doesn't
      seem to be any sort of "control" built into these menus.  In other words, the only thing that changes in Au3Info when you hover over different options is the
      coordinates of the mouse--there aren't any unique control IDs or texts to my knowledge that differentiate between different settings or menus.  I don't know how to search for text in a menu and get an index or anything like that.  I've attached my code at the bottom and commented-out two ideas I had for reading the status and acting accordingly after "Send (Q)".  Neither of which were fruitful. 
      2. Is there an alternative to the overall method I've chosen that is simpler and more robust?  It seems like there must be an alternative path to these settings besides the system tray, but I don't know of any such paths.   The final script is going to be used on a number of computers which may have the McAfee icon either hidden or visible in the system tray, but currently my script only works if it is visible.  I haven't figured out how to access hidden icons with mouse clicks yet. 
      I should also mention that most of my code for step 1 (find the McAfee icon) comes from something I found online.  I've stared at it for a while, and I think I know how it works, but I wouldn't have known those GUI commands existed and wouldn't have been able to write that bit of code on my own.    I don't want you to overestimate my understanding of AutoIt.  Sorry for the long post, just wanted to provide all the relevant info. 
      Any advice you can offer would be greatly appreciated!  Thanks in advance.
      #cs AutoIt McAfee disable #ce #Include <GuiToolBar.au3> #Include <GUIConstants.au3> Local $Array[3] For $Element In $Array Global $hSysTray_Handle, $iSystray_ButtonNumber Global $sToolTipTitle = "McAfee status: OK" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle) If $iSystray_ButtonNumber = 0 Then MsgBox(16, "Error", "Icon not found in system tray") Exit Else Sleep(500) _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right") EndIf Send( "Q" ) ;$DropDownHandle = Controlgethandle( "", "Host IPS - on", "") ;$text = ControlGetText( "", "Host IPS - on", "") ;If "Host IPS - on" = 1 Then ; Send( $Element ) ;EndIf Next Exit ;........ Func Get_Systray_Index($sToolTipTitle) ; Find systray handle $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') If @error Then MsgBox(16, "Error", "System tray not found") Exit EndIf ; Get systray item count Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSystray_ButCount = 0 Then MsgBox(16, "Error", "No items found in system tray") Exit EndIf ; Look for wanted tooltip For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop Next If $iSystray_ButtonNumber = $iSystray_ButCount Then Return 0 ; Not found Else Return $iSystray_ButtonNumber ; Found EndIf EndFunc  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.