后台作业,启动从未启动的流程

时间:2020-09-25 12:32:52

标签: powershell

Register-ObjectEvent `
 -InputObject $balloon `
 -EventName Click `
 -SourceIdentifier BalloonClicked `
 -ErrorAction Inquire `
 -Action {
  [Globals]::RequestEnd = $true
  Start-Process "explorer.exe"
 } | Out-Null
 while (-not [Globals]::RequestEnd) {
   Start-Sleep -Milliseconds 100
 }

我有这段代码,当给定的通知出现时,该进程将启动进程 explorer.exe (并同时停止脚本)。当脚本以其名称.\script.ps1启动时,我可以单击NotifyIcon并显示explorer.exe。但是,当脚本Start-Job -FilePath .\script.ps1像后台任务一样启动时,该脚本似乎永远不会结束,并且进程也永远不会显示。

image of the output job still in running state

那么,在后台作业中,如何启动流程?

0 个答案:

没有答案
相关问题