I would like to access my web browser using a batch file.Is there a way of knowing whether any web browser is open or not using a batch file? Take any browser for example.
Asked
Active
Viewed 3,287 times
2
-
1possible duplicate of [How to check if a process is running via a batch script](http://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script) – Sony Mathew Apr 16 '15 at 11:57
2 Answers
3
Yes, there is a way. The command tasklist
returns you a list of running tasks:
@ECHO OFF
SET running=0
FOR /f "tokens=*" %%A IN ('tasklist^ /v^| findstr /i /c:"firefox32.exe"') DO SET running=1
IF %running%==1 ECHO Firefox is running!
PAUSE
This checks whether Firefox is running.

MichaelS
- 5,941
- 6
- 31
- 46
-
I have just started using stackoverflow. An up vote requires 15 reputation it seems – VaM999 Apr 16 '15 at 12:08
-
The script is not working. I want to check for chrome and i typed thisFOR /f "tokens=*" %%A IN ('tasklist^ /v^| findstr /i /c:"chrome.exe"') DO SET running=1 – VaM999 Apr 17 '15 at 08:42
-
Please post your code. If your are checking more than one browser and always using the variable `running` you have to have to add `SETLOCAL EnableDelayedExpansion`in the second line and access `running` as `!running!` instead of `%running%`. – MichaelS Apr 17 '15 at 10:28
1
Try Doing: (you can use 'Setlocal EnableDelayedExpansion' for displaying a variable as !variable! instead of %variable%. In this case, I won't do it.)
@echo off
echo ' > %userprofile%\Desktop\tasklist1.txt
tasklist >> %userprofile%\Desktop\tasklist1.txt
for /f "tokens=1 delims= " %%a in ('findstr /i "' firefox.exe" %userprofile%\Desktop\tasklist1.txt') do (
set running=%%a
)
if %running% == ' (
echo Firefox is not running.
) else (
echo Firefox is running!
)
pause

PanosJr
- 11
- 2