This uses tasklist in XP Pro and higher:
@echo off
tasklist /fi "imagename eq example.exe" /nh |find /i /c "example.exe" > "%temp%\variable.txt"
set /p value=<"%temp%\variable.txt"
if %value% equ 1 taskkill /f /im example.exe
ECHO continue
@echo off
You can do it with one line and no temp file also - this uses another findstr filter to check if the number is a single 1
on a line and then &&
is a conditional operator that will launch taskkill if it does find 1
.
@echo off
tasklist /fi "imagename eq example.exe" /nh |find /i /c "example.exe"|findstr "^1$" >nul && taskkill /f /im example.exe
ECHO continue
@echo off