Runs an external program under the context of a different user.
RunAs ( "username", "domain", "password", logon_flag, "program" [, "workingdir" [, show_flag [, opt_flag]]] )
| username | The username to log on with. |
| domain | The domain to authenticate against. |
| password | The password for the user. |
| logon_flag | 0 - Interactive logon with no profile. 1 - Interactive logon with profile. 2 - Network credentials only. 4 - Inherit the calling process's environment instead of the user's environment. |
| program | The full path of the program (EXE, BAT, COM, or PIF) to run (see remarks). |
| workingdir | [optional] The working directory. If not specified, then the value of @SystemDir will be used. This is not the path to the program. |
| show_flag | [optional] The "show" flag of the executed program: @SW_HIDE = Hidden window (or Default keyword) @SW_MINIMIZE = Minimized window @SW_MAXIMIZE = Maximized window |
| opt_flag | [optional] Controls various options related to how the parent and child process interact. 0x1 ($STDIN_CHILD) = Provide a handle to the child's STDIN stream 0x2 ($STDOUT_CHILD) = Provide a handle to the child's STDOUT stream 0x4 ($STDERR_CHILD) = Provide a handle to the child's STDERR stream 0x8 ($STDERR_MERGED) = Provides the same handle for STDOUT and STDERR. Implies both $STDOUT_CHILD and $STDERR_CHILD. 0x10 ($STDIO_INHERIT_PARENT) = Provide the child with the parent's STDIO streams. This flag can not be combined with any other STDIO flag. This flag is only useful when the parent is compiled as a Console application. 0x10000 ($RUN_CREATE_NEW_CONSOLE) = The child console process should be created with it's own window instead of using the parent's window. This flag is only useful when the parent is compiled as a Console application. |
| Success: | The PID of the process that was launched. |
| Failure: | Returns 0 and sets @error to non-zero. |
; Fill in the username and password appropriate for your system.
Local $sUserName = "Username"
Local $sPassword = "Password"
; Run a command prompt as the other user.
RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec, @SystemDir)