Runs an external program under the context of a different user and pauses script execution until the program finishes.
RunAsWait ( "username", "domain", "password", logon_flags, "filename" [, "workingdir" [, flag]] )
Parameters
| username | The username to log on with. |
| domain | The domain to authenticate against. |
| password | The password for the user. |
| logon_flags | 0 - Interactive logon with no profile. 1 - Interactive logon with profile. 2 - Network credentials only. 4 - Inherit the calling processes environment instead of the user's. |
| filename | The name of the executable (EXE, BAT, COM, PIF) to run. |
| workingdir | [optional] The working directory. If not specified, then the value of @SystemDir will be used. |
| flag | [optional] The "show" flag of the executed program: @SW_HIDE = Hidden window (or Default keyword) @SW_MINIMIZE = Minimized window @SW_MAXIMIZE = Maximized window |
Return Value
| Success: | Returns the exit code of the program that was run. |
| Failure: | Returns 0 and sets @error to non-zero. |
Remarks
It is important to specify a working directory the user you are running as has access to, otherwise the function will fail.
Related
ProcessWait, ProcessWaitClose, Run, RunWait, ShellExecute, ShellExecuteWait, RunAs
Example
; Fill in the username and password appropriate for your system.
Local $sUserName = "Username"
Local $sPassword = "Password"
; Run a command prompt as the other user.
Local $pid = RunAsWait($sUserName, @ComputerName, $sPassword, 0, @ComSpec, @SystemDir)
; Wait for the process to close.
ProcessWaitClose($pid)
; Show a message.
MsgBox(0, "", "The process we were waiting for has closed.")