在不关闭服务的情况下停止子进程
Stopping a Sub process without closing the Service
我正在使用 PowerShell 启动进程命令将 运行 ps1 文件作为服务。以下是启动此过程的行:
start-process PowerShell.exe -arg C:\scripts\scrtip_name.ps1 -WindowStyle Hidden
如何在不完全关闭 PowerShell 服务的情况下停止 "JUST THIS EXECTUTION",因为它可能同时用于其他进程。
如果将 Start-Process
与 -PassThru
标志一起使用,您可以获得 PID,如下所示:
$app = start-process PowerShell.exe -arg C:\scripts\scrtip_name.ps1 -WindowStyle Hidden - PassThru
然后像这样关闭进程:
Stop-Process $app.Id
此致
我正在使用 PowerShell 启动进程命令将 运行 ps1 文件作为服务。以下是启动此过程的行:
start-process PowerShell.exe -arg C:\scripts\scrtip_name.ps1 -WindowStyle Hidden
如何在不完全关闭 PowerShell 服务的情况下停止 "JUST THIS EXECTUTION",因为它可能同时用于其他进程。
如果将 Start-Process
与 -PassThru
标志一起使用,您可以获得 PID,如下所示:
$app = start-process PowerShell.exe -arg C:\scripts\scrtip_name.ps1 -WindowStyle Hidden - PassThru
然后像这样关闭进程:
Stop-Process $app.Id
此致