2017-04-07 35 views
0

我有我想要的過程殺:如何使用powershell強行殺死一個進程?

$ 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強行殺掉一個進程?

+3

'停過程-force'? – 4c74356b41

+0

@ 4c74356b41出於某種原因,我發現文檔不包括-force,但你說得對 - 列表,作爲一個答案(一個鏈接到https://msdn.microsoft.com/en-us/powershell/ reference/5.1/microsoft.powershell.management/stop-process),我將其標記爲正確。 – mikemaccana

回答

0

help Stop-Process -online

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 

獎金玉米片服用,Get-Command -ParameterName *force將顯示所有cmdlet包括該 PARAM。

0

如果你這樣做了嗎?

(get-process -Name SourceTree).Kill()