使用一个不同的用户运行一个外部程序文件.
RunAs ( "用户名", "域名", "密码", 登录标志, "程序" [, "工作目录" [, 显示标志 [, 可选标志 ]]] )
用户名 | 需要使用的用户名. |
域名 | 用于甄别的域名称. |
密码 | 用户的密码. |
登录标志 | 0 - 不加载配置文件的交互式登录. 1 - 加载配置文件的交互式登录. 2 - 只是网络认证. 4 - 继承调用程序的环境变量替换用户的环境变量. |
程序 | 程序所在的完整路径(文件格式为 EXE,BAT,COM 或 PIF). |
工作目录 | [可选参数] 程序工作目录. 如果不指定, 将会被设置为 @SystemDir .这个路径不一定指向程序所在路径. |
显示标志 | [可选参数] 执行程序的 "显示" 标志: @SW_HIDE = 隐藏窗口 (或者 Default 关键字) @SW_MINIMIZE = 最小化的窗口 @SW_MAXIMIZE = 最大化的窗口 |
可选标志 | [可选参数] 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. |
成功: | 运行的进程的 PID . |
失败: | 返回 0 并设置 @error 为一个非0值 |
; 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)