taskkill to differentiate 2 images by path

a 夏天 提交于 2019-12-05 00:25:29

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()
Akira Yamamoto

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!