Swabynnaf Posted April 26, 2007 Posted April 26, 2007 Hi I'm trying to write some registry keys by using the RunAsSet command to elevate the users privileges then write the registry entries and then set the user privileges back to the current logged in user. I've tried this using the script below. ; Set the RunAs parameters to use domain Loginscript account RunAsSet($Username2, $Domain2, $Password2) ; Initialization of the variables $Username2 = "LoginScript" $Password2 = "LoginScript" $Domain2 = "Domain" RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "OriginalWallpaper", "REG_SZ", "C:\WINDOWS\web\Wallpaper\Wallpaper.bmp") ; Write registry Eetries for Wallpaper to current and default users RegWrite("HKEY_USERS\.DEFAULT\Control Panel\Desktop", "OriginalWallpaper", "REG_SZ", "C:\WINDOWS\web\Wallpaper\Wallpaper.bmp") ; Reset user's permissions RunAsSet() I have 2 problems. 1. The HKEY_USERS entry doesn't appear therefore the users haven't got the rights to enter it (ie the runas isn't working). 2. When I use the RunAs does the HKEY_CURRENT_USER become the LoginScript user (ie the one with the elevated privileges) or does it insert the entry for the currently logged in user? Help would be appreciated or if there's a better way then I'm all ears. Basic Plan Login script run on a domain server to insert backgrounds and copy the file to local drives, set keys to point to background. I know I can use GP for this but it isn't very good and I'd rather try it this way. Eventually the script will check for the wallpaper and won't copy it across if it's not needed but I need to get the permissions sorted first. Thanks in advance. Swabynnaf
MHz Posted April 26, 2007 Posted April 26, 2007 (edited) RunAsSet() allows running a process as admin. Thus, Run() and RunWait() (and perhaps ShellExecute() too) have the admin privilages. What you can do is restart your script as admin by using a commandline switch. Look here to what Larry posted as a solution. http://www.autoitscript.com/forum/index.ph...st&p=333972 Edited April 26, 2007 by MHz
Administrators Jon Posted April 26, 2007 Administrators Posted April 26, 2007 This is the script I've added as an example to RunAsSet. ; This example will rerun itself with admin rights on using a local account ; Note on Vista this may not work as even though the user is admin it may ; not be elevated even after the RunAs call. In that case use #RequireAdmin ; at the top of the script. ; Are we already admin? If Not IsAdmin() Then RunAsSet('USER', @Computername, 'PASSWORD') Run('"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir) Exit EndIf MsgBox(0, 'Message', 'Now running with admin rights.') Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
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