Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: RunWithLogon run under switch back local user account
Any ideas of how this can be done?
So if you need to execute code as the 'logged in' user account after running as 'administrator'. You will need to specify @WAIT in the RunWithLogon statement. This tells the first script/instance to wait for the second Admin instance to finish. Then you can execute any further code you want to run as the current user, after the RunWithLogon statement. See the lines commented with ****** .
;This script will give itself admin privileges moiparams=IntControl(1006,0,0,0,0) if StrIndexNC(moiparams,"URADMIN",0,@fwdscan) ; Already launched as admin param0 = param0 -1 ; Remove the URADMIN param from further consideration else ; need admin privileges if WinVersion(5) >= "2-5-0" ;Win2000 or newer ;NOTE: For security reasons *always* assign the password ; to a variable and then use the variable in the RunWithLogon ; statement. NEVER hardcode the password into the ; RunWithLogon statement or else the password my be ; exposed if the RunWithLogon fails on some kind of error ; This is also a good idea with the userid and domain ; information runas_user = "Administrator" runas_pswd = "password" runas_domain = ComputerNameGet(0) moi=WinExename("") moiparams=strcat(moiparams, " URADMIN") ;******{ ADD CODE HERE YOU WANT TO RUN BEFORE YOUR ADMIN SCRIPT RUNS } ****** RunWithLogon(moi, moiparams, "", @NORMAL, @WAIT, runas_user, runas_domain, runas_pswd,0) ;****** { ADD CODE HERE YOU WANT TO RUN AFTER YOUR ADMIN SCRIPT EXITS } ****** exit else Message("RunWithLogon","Is not designed for this platform.") exit endif endif ;------------------------------- ; Running in Admin mode now. ;------------------------------- ;****** { ADD CODE HERE YOU WANT TO EXECUTE IN ADMIN MODE } ****** exit
Article ID: W15168
File Created: 2009:03:25:13:52:34
Last Updated: 2009:03:25:13:52:34