我正在尝试使用给定凭据的powershell脚本运行start-process.然而,命令失败并出现以下错误:
Start-Process : This command cannot be executed due to the error: Access is denied
Run Code Online (Sandbox Code Playgroud)
这是完整的错误日志:
18-Jun-2015 11:48:54 Start-Process : This command cannot be executed due to the error: Access is den
18-Jun-2015 11:48:54 ied.
18-Jun-2015 11:48:54 At C:\Windows\system32\config\systemprofile\AppData\Local\Temp\PRISMA-AMR-JOB1-
18-Jun-2015 11:48:54 87-ScriptBuildTask-8569094554411403512.ps1:38 char:18
18-Jun-2015 11:48:54 + Start-Process <<<< C:\Windows\System32\cmd.exe -arg "/C" -Credential $cr
18-Jun-2015 11:48:54 edential
18-Jun-2015 11:48:54 + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp
18-Jun-2015 11:48:54 erationException
18-Jun-2015 11:48:54 + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
18-Jun-2015 11:48:54 ommands.StartProcessCommand
Run Code Online (Sandbox Code Playgroud)
这是错误的PowerShell调用的样子:
Start-Process C:\Windows\System32\cmd.exe …Run Code Online (Sandbox Code Playgroud) Start-Process和 和有Invoke-Item什么区别?我注意到你不能Invoke-Item chrome。我认为这Invoke-Item是专门针对具有给定文件路径的文件。但是使用Invoke-Item而不是有什么好处吗Start-Process(除了打字ii比打字快start)?
为什么Start-Process powershell.exe { Read-Host }有效,但Start-Process pwsh.exe { Read-Host }不起作用?
我知道 的-ArgumentList切换Start-Process,但是当涉及转义引号时,它使事情变得更加复杂:
PowerShell 7.0.3 和 7.2.0-preview.3:
Start-Process pwsh.exe -ArgumentList '-Command "& {
''Hello World.''
Read-Host
}"' -Verb RunAs
Run Code Online (Sandbox Code Playgroud)
PowerShell 5.1:
Start-Process powershell.exe {
'Hello World.'
Read-Host
} -Verb RunAs
Run Code Online (Sandbox Code Playgroud)
另一方面,当创建新的 PowerShell 会话(不带Start-Process)时,仍然可以使用脚本块:
pwsh.exe {
'Hello World.'
Read-Host
}
Run Code Online (Sandbox Code Playgroud)
我在这里遗漏了一些东西还是有更好/不同的方法允许脚本块与脚本的其余部分并行执行?
powershell start-process scriptblock powershell-core powershell-7.0
这应该在 3 岁以上的 PowerShell 中正常工作。我需要运行两个进程:wuapp.exe 和带有 ScreenSaver 选项卡的 desk.cpl。我遇到的问题是,一旦我启动 wuapp.exe,进程名称就会在任务管理器中显示为 explorer.exe - 当前代码适用于 wuapp.exe,但不适用于每台机器。另一件事是当我杀死 rundll32 时,其他应用程序也会关闭。你有什么建议?
$wshell = New-Object -ComObject Wscript.Shell
Start-Process wuapp.exe
(New-Object -comObject Shell.Application).Windows() | foreach-object {$_.quit()}
Start-Process rundll32 desk.cpl,InstallScreenSaver
Stop-Process -ProcessName rundll32* -Force
Run Code Online (Sandbox Code Playgroud) ssomebody可以帮助在同一窗口中运行新进程吗?
$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")
Run Code Online (Sandbox Code Playgroud)
-NoNewWindow不起作用,但没有-Credential $ credential它工作正常..我该如何解决这个问题?