我有一个我想杀的过程:
$ ps Sourcetree
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
1311 116 136720 137804 57.45 1044 1 SourceTree
将其发送至Stop-Process
, aka kill
:
$ ps Sourcetree | kill
运行没有错误。但这个过程并未被杀死:
$ ps Sourcetree
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
1311 116 136720 137804 57.45 1044 1 SourceTree
如何使用PowerShell强制终止进程?
答案 0 :(得分:1)
Stop-Process [-Id] <Int32[]> [-PassThru] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
-Force
Stops the specified processes without prompting for confirmation.
By default, Stop-Process prompts for confirmation before stopping
any process that is not owned by the current user.
To find the owner of a process, use the Get-WmiObject cmdlet to
get a Win32_Process object that represents the process, and then
use the GetOwner method of the object.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Bonus nachos,Get-Command -ParameterName *force
将显示包含强制参数的所有Cmdlet。
答案 1 :(得分:0)
为了更好地了解cmdlet以及它们的功能,您始终可以Get-Help cmdlet
查看它支持的内容。
Get-Help Stop-Process
或者只是将cmdlet输入搜索引擎,这很可能会引导您访问官方帮助文章。
答案 2 :(得分:0)
如果你这样做?
(get-process -Name SourceTree).Kill()