0

Right now I have a batch file I created that simple kills a chrome browser and opens up a new one to a particular homepage. I run this on a 5 minute interval with some added software that runs it if there is no activity for 5 minutes. I use this as a timeclock.

I am having some issues with the browser closing and reopening all the time. I figure I can make this script more effiecent by changing a few things.

Instead of closing and open a new browser every 5 minutes I would like to check first if the chome browser is already open and if it is then simple refresh it, otherwise open it.

Here is my current script

@echo off

taskkill /f /im chrome.exe

start "chrome" "C:\Program Files\Google\Chrome\Application\chrome.exe" --kiosk "http://www.example.com/sd/clockin/testclockin.php"
Cesar Bielich
  • 4,754
  • 9
  • 39
  • 81

1 Answers1

0

To check if Chrome is currently running, you can use the tasklist command.

tasklist | findstr chrome.exe || echo Chrome is not running

the code after || will only run if an errorlevel is set by the previous command, i.e. if chrome.exe doesn't show up in tasklist. You can use && to execute only if an errorlevel was not set.

You can also just check the errorlevel using a simple if statement -

if %errorlevel%==1 echo Chrome is running

Obviously chrome is closing because you are running the taskkill command. I assume you want to refresh the open page. You may need to look into using VBScript for this. This should help - refresh firefox from .bat file/ command.

Community
  • 1
  • 1
unclemeat
  • 5,029
  • 5
  • 28
  • 52