我想在windows-7 64位机器上从powershell脚本运行EXE。在这个脚本中,我想以另一个用户身份运行exe。它在用户调用脚本是实际用户时起作用。但在我的情况下,这个PowerShell脚本将从系统用户帐户执行,而系统用户脚本不起作用。这里用一个简单的代码打开记事本。此代码对系统用户失败。无法从系统用户的PowerShell中运行EXE
$username = 'MyDomain\MyUser'
$password = 'mypswd'
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
Start-Process -Credential $cred "notepad.exe"
我已经将执行策略设置为无限制。当我运行此脚本系统用户,然后我得到错误的
Start-Process : This command cannot be executed due to the error: Access is den ied. At D:\temp\trythis.ps1:4 char:14 + Start-Process <<<< -Credential $cred "notepad.exe" + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp erationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C ommands.StartProcessCommand
是否有我可以运行此脚本系统用户什么办法?
我试过你的方法,但我仍然得到同样的问题。要重现此问题,我正在使用sysinternals的psexec实用程序。我首先在命令提示符“psexec -i -s powershell”中运行此命令,然后在powershell提示符下输入问题中显示的代码。 – 2012-07-20 12:27:57
您是否使用PsExec远程执行此操作?如果你是,那么可能会有不同的权限集。如果你不是,那么使用PsExec的目的是什么? – 2012-07-20 13:17:11
是的,我正在远程执行此操作。实际上,这将由我们的集成服务器调用。 – 2012-07-23 10:12:14