问题
I get two results when I run this:
tasklist /FI "imagename eq PROCESS.exe"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
PROCESS.exe 2760 Console 1 8,156 K
PROCESS.exe 20160 Console 1 9,060 K
But I only want to kill ONE of them...
If I open up the Task Manager, I can see that each of my processes have different descriptions.
So all I need to do, is somehow filter by process description.
Can anyone help, please?
Thank you!
回答1:
Use the following to distinguish the processes according to their own process ID and their parent process ID:
wmic process get processid,parentprocessid,executablepath | find "PROCESS"
This way, you can find the process ID to kill.
wmic
grants access to additional process properties.
Use wmic process get /?
to find out what is available.
Another potentially helpful tool is PsList of Microsoft/Sysinternals.
回答2:
If you want to filter your process list by the window title, just use
tasklist /FI "windowtitle eq Title"
As addition to @Axel's answer with WMI - the same for description
:
WMIC Process WHERE "Description='Only One'" GET ProcessID
And in VBS:
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Process WHERE Description = 'My Desc'",,48)
For Each objItem in colItems
'Do Stuff
Next
Another possible value for description is the assembly's description which is retrievable with PowerShell. Use Get-Process to obtain the assembly path and retrieve its description with [System.Diagnostics.FileVersionInfo]::GetVersionInfo($File).FileDescription
.
来源:https://stackoverflow.com/questions/37434897/find-a-windows-process-based-on-its-description-using-cmd