我正在尝试使用其他用户的凭据通过PowerShell 1.0运行可执行文件。我目前的脚本如下:
$username = "adminuser"
$password = "thepassword"
$secstr = ConvertTo-SecureString -String $password -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $secstr
Start-Process powershell.exe -verb runas -Credential $cred -File C:\Users\Public\myexecutable.exe
我收到的错误如下:
Error: Start-Process : This command cannot be run due to the error: The handle is invalid.
At C:\Users\Public\privy2.ps1:8 char:1
+ Start-Process powershell.exe -Credential $cred
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
使用不带凭据的命令时,脚本可以运行,可执行文件运行:
Start-Process powershell.exe -verb runas -File C:\Users\Public\myexecutable.exe
关于我为何获得The handle is invalid error
的任何想法?
每.NET Process Start Process Error using credentials (The handle is invalid),我尝试添加重定向,但同样的错误仍然存在。
答案 0 :(得分:0)
您需要以管理员身份打开Powershell。只需右键单击Powershell,然后单击“以管理员身份运行”。它应该可以正常工作,并且您不会看到The handle is invalid error
。