问题
How to kill a process by name and orginiated from a particular path using taskkill?
taskkill /F /IM
certainly it cant differentiate 2 process started from two different locations C:\Dir1 and C:\Dir2
Does tasklist has any switch to get the path name
回答1:
taskkill
cannot do it. But you could use PowerShell if it's an option:
(Get-WmiObject Win32_Process | Where-Object { $_.Path.StartsWith('C:\Dir1') }).Terminate()
回答2:
Based on Joey's answer:
wmic Path win32_process Where "CommandLine Like '%-jar selenium-server.jar%'" Call Terminate
This way I avoid NullReferenceException when Path is null (don't know why) and does not need PowerShell.
Ref: https://superuser.com/questions/52159/kill-a-process-with-a-specific-command-line-from-command-line
回答3:
Use the following command (it works even without powershell):
wmic process where ExecutablePath='C:\\Dir1\\image.exe' delete
NOTE: ExecutablePath is accessable for all processes only if you run wmic
as administrator on Windows 8
回答4:
Your case seems to be when you have custom services with same process name installed on the machine from different paths. If this is indeed the scenario, you probably have different Service Names which can be used as an additional filter.
See Syntax:
taskkill /S {REPLACE_WITH_SERVER_IP_OR_NAME} /F /FI "IMAGENAME eq {REPLACE_WITH_PROCESS_NAME}" /FI "SERVICES eq {REPLACE_WITH_SERVICENAME}"
See Example:
taskkill /S 10.10.1.1 /F /FI "IMAGENAME eq tomcat7.exe" /FI "SERVICES eq tomcatServiceEngine"
For list of all available filters, please visit taskkill command
来源:https://stackoverflow.com/questions/13524303/taskkill-to-differentiate-2-images-by-path