I've inherited an environment in which two different processes use identical names but their executable files are stored in different file paths. None, one, the other, or both may be running at any time.
When I perform certain operations (like patching), I want the process associated with the patching directory to be terminated but not the other one.
Using a variety of different techniques, I have no trouble terminating the processes based upon process name, such as (less elegantly without using powershell):
echo Checking for procname process... tasklist /FI "IMAGENAME eq procname .exe" | !windir!\system32\find /I "procname.exe" set EL=!ERRORLEVEL! if !EL! EQU 0 ( echo Killing procname process... TASKKILL /F /FI "IMAGENAME eq procname.exe" )
or more elegantly (using powershell)
powershell Clear-Host powershell Stop-Process -name procname
However, both of these methods kill both processes if they're running.
Instead of killing these processes based upon their process name, how can I kill a process based upon the path to their executable?