0

有人可以帮助在同一窗口中运行新进程吗?

$credential = Get-Credential

Start-Process powershell.exe -Credential $credential -NoNewWindow -ArgumentList ".\ListScript.ps1" -Wait

Write-Host "Press any key to continue ..."

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

-NoNewWindow 不起作用,但没有 -Credential $credential 它可以正常工作。我该如何解决?

4

1 回答 1

5

Windows credentials are applied at the process level. Your first process is operating under your credentials.

If you use Start-Process without specifying other credentials, the new process can run under your existing process.

If you use Start-Process with -Credential , the new process must be launched in a process to use these new credentials. That is why you are getting a new window when using the -Credential argument.

Long story short, behavior by design. That is the way Windows handles processes and credentials. It must open a new process/window with new credentials.

于 2012-12-19T12:33:09.050 回答