简体   繁体   English

PowerShell启动过程

[英]PowerShell Start-Process

Can ssomebody help ti run new process in the same window?? 有人可以帮助ti在同一窗口中运行新进程吗?

$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 doesn't work, but without -Credential $credential it works fine.. How can I fix that? -NoNewWindow不起作用,但是如果没有-Credential $ credential,它将无法正常工作。如何解决此问题?

Windows credentials are applied at the process level. Windows凭据在流程级别应用。 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. 如果您在不指定其他凭据的情况下使用Start-Process,则新过程可以在现有过程下运行。

If you use Start-Process with -Credential , the new process must be launched in a process to use these new credentials. 如果将Start-Process与-Credential一起使用,则新进程必须在使用这些新凭据的进程中启动。 That is why you are getting a new window when using the -Credential argument. 这就是为什么在使用-Credential参数时会得到一个新窗口的原因。

Long story short, behavior by design. 长话短说,行为是设计使然。 That is the way Windows handles processes and credentials. 这就是Windows处理进程和凭据的方式。 It must open a new process/window with new credentials. 它必须使用新的凭证打开一个新的进程/窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM