【发布时间】:2014-08-21 17:25:59
【问题描述】:
我有一个脚本可以以特定用户身份启动另一个 ps1 脚本,该用户在目录上执行简单的 dir,并且当它运行时,会出现一个带有目录内容的单独 cmd 窗口。
$encpwd = Get-Content C:\path\to\creds.txt
$passwd = ConvertTo-SecureString $encpwd
$cred = new-object System.Management.Automation.PSCredential 'theuser',$passwd
Start-Process c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -Credential $cred -ArgumentList '-noexit','-File', 'C:\path\to\script\test.ps1'
我的目标是以特定用户身份启动应用程序。所以首先我想用notepad.exe测试所以我把最后一行改成:
Start-Process c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -Credential $cred -ArgumentList '-noexit','-File', 'C:\windows\system32\notepad.exe'
我得到的只是一个快速消失的命令窗口,无法判断是否有错误等。我还尝试调用一个调用记事本的 ps1 脚本并得到相同的结果,即使它自己是新脚本调用记事本就好了。
谁能解释我哪里出错了,谢谢
【问题讨论】:
标签: windows powershell credentials runas