约 1099 字

约 5 分钟

#PowerShell 的 Stop-Process 命令

Stop-Process [-Id] <Int32[]> [-PassThru] [-WhatIf]
Stop-Process -Name <String[]> [-PassThru] [-WhatIf]
Stop-Process [-InputObject] <Process[]> [-PassThru] [-WhatIf]

功能

终止本机进程。可以按进程对象、进程 ID 或名称指定对象。

类型

Cmdlet,属于 Microsoft.PowerShell.Management。

参数

  • -InputObject 直接指定 Process 对象,也可通过管道传入。
  • -Id 指定进程 ID。-Name 支持通配符,可能匹配多个进程。
  • -PassThru 返回进程对象。-WhatIf 可以预览操作。

#示例

终止本例启动的子进程

$pwshPath = (Get-Process -Id $PID).Path
$child = Start-Process -FilePath $pwshPath `
    -ArgumentList '-NoProfile -NonInteractive -Command "Start-Sleep -Seconds 30"' -PassThru
Stop-Process -InputObject $child
$child.WaitForExit(5000)
True

WaitForExit(5000) 最多等待 5 秒,并用布尔值表示该子进程是否已退出。

#推荐阅读

更新: 2026/11/27

作者: planc

创建: 2026/11/27