如何使用powershell强行终止进程?

问题描述 投票:0回答:4

我想杀死一个进程:

$ 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
,又名
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强行杀死进程?

windows powershell process
4个回答
1
投票

使用

-Force

ps -force Sourcetree | kill

取自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
将显示包含 force 参数的所有 Cmdlet。


1
投票

如果你这么做了?

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

0
投票

为了更好地理解 cmdlet 及其功能,您可以随时执行

Get-Help cmdlet
并查看它的功能\支持。

Get-Help Stop-Process

或者只需在搜索引擎中输入 cmdlet,这很可能会引导您找到官方帮助文章。

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/stop-process


0
投票

最简单的正确答案是:

Get-Process SourceTree | Stop-Process -Force

“SourceTree”是进程名称。

© www.soinside.com 2019 - 2024. All rights reserved.