Solved How do I do this, please help,

September 15, 2017 at 16:05:12
Specs: Windows 10
What I want to do is that, when it detects that chrome.exe is running, I want it to close chrome.exe without using errorlevel. Thanks in advance!

@echo off
tasklist /fi "imagename == chrome.exe"
if "imagename==chrome.exe" taskkill /im chrome.exe
pause

See More: How do I do this, please help,

Reply ↓  Report •

#1
September 18, 2017 at 19:57:12
1) If you're really using Windows 10, you should use VBScript or PowerShell instead of batch script. Batch won't teach you anything viable, and Microsoft has started to depreciate CMD (and thus batch files) in favor of PowerShell.

2) If you want a program killed, just try to kill the program. After all, taskkill will have to look for the program anyways. You'll either get it dead, or not.

taskkill /im chrome.exe 2>NUL

How To Ask Questions The Smart Way


Reply ↓  Report •

#2
September 19, 2017 at 02:34:18
✔ Best Answer
@echo off
for /f %a in ('tasklist /NH /FI "IMAGENAME eq chrome.exe"') do if "%a" equ "chrome.exe" taskkill /f /im chrome.exe>nul
exit /b

::Do you want it to loop?

Simple solutions are often the best

message edited by hidde663


Reply ↓  Report •

#3
September 19, 2017 at 05:02:37
Yes, that's it, but you need to add another %, it's %%a not %a,so it looks something like this:
@echo off
for /f %%a in ('tasklist /NH /FI "IMAGENAME eq chrome.exe"') do if "%%a" equ "chrome.exe" (
taskkill /f /im chrome.exe>nul )
exit

Thank you!!


Reply ↓  Report •

Related Solutions

#4
September 19, 2017 at 05:34:44
Just a warning, but you've just created a race condition. Mine also has the same race condition, but at least its window is the smallest possible with batch.

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •

Ask Question