Batch File Loop to Check for Process

Microsoft Windows 7 home premium 64-bit
September 17, 2010 at 19:06:29
Specs: Windows 7, AMD Phenom II x4 955 3.2GHZ - 4GB RAM
Hello all,

I am trying to write a batch file that continually checks for a process and, if the process is not running, enables my second monitor. I am using a program called MurgeeMon to control the monitors. It isn't working unfortunately... not quite sure what the problem is. The first part of the batch file works (i.e. the secondary monitor is disabled) but the loop doesn't seem to be working properly. Here is the code:

echo off

start "" "C:\Program Files (x86)\MurGeeMon\MurGeeMon.exe" 6
start "" "D:\Games\Steam\SteamApps\common\fallout 3 goty\FalloutLauncher.exe"

:loopstart

call wait 1

set process_1="Fallout3.exe"
set process_2="FalloutLauncher.exe"

set ignore_result=INFO:
for /f "usebackq" %%A in (`tasklist /nh /fi "imagename eq %process_1%"`) do if not %%A==%ignore_result% Exit
for /f "usebackq" %%A in (`tasklist /nh /fi "imagename eq %process_2%"`) do if not %%A==%ignore_result% Exit

start "" "C:\Program Files (x86)\MurGeeMon\MurGeeMon.exe" 5
goto end

goto loopstart

:END

So the batch file SHOULD check to see if fallout 3 or the fallout 3 launcher is running, and if neither of them are running, enable the second monitor (through MurgeeMon). The 'call wait 1' is just a batch file to make the loop execute only once every second.

The program MurgeeMon parameters are definitely correct, as are the process names of fallout and the fallout launcher.

I'm pretty new to Batch files and DOS - please be nice and laymen like when explaining where I have gone wrong!

Thanks,
GreyFox


See More: Batch File Loop to Check for Process

Report •


#1
September 17, 2010 at 23:57:00
I appreciate you are NEW but DOS does not come into the equation, Windows 7 does not have MS-DOS period, hence why your post was moved here from the other forum, It is NT Command Prompt:

I hope some one will point you in the correct direction...


Report •

#2
September 19, 2010 at 02:34:41
Thanks for the push towards the right direction ... Having this thread in the right section is probably a good idea... ha ha.

Hey I solved my problem! Got a little confused in the logic of the FOR loop. Changed it to this:

echo off
setlocal EnableExtensions

start "" "C:\Program Files (x86)\MurGeeMon\MurGeeMon.exe" 6
start "" "D:\Games\Steam\SteamApps\common\fallout 3 goty\FalloutLauncher.exe"

:start

call wait 1

set process_1="Fallout3.exe"
set process_2="FalloutLauncher.exe"
set ignore_result=INFO:

for /f "usebackq" %%A in (`tasklist /nh /fi "imagename eq %process_1%"`) do if not %%A==%ignore_result% goto Start
for /f "usebackq" %%B in (`tasklist /nh /fi "imagename eq %process_2%"`) do if not %%B==%ignore_result% goto Start

start "" "C:\Program Files (x86)\MurGeeMon\MurGeeMon.exe" 5
goto end

:end


Works a charm. Anyone who has to disable a monitor before playing a game or opening up an exe just replace the "Fallout3.exe" with the process name you must run with only one monitor and comment out, or delete, the "set process_2..." line and the second FOR loop.


Report •

#3
September 19, 2010 at 02:37:53
P.S you will need to download MurgeeMon (find it through Google) and make a batch file called wait.bat with certain parameters.

Google 'wait.bat file' to find out how to create your own delay bat file for win 7.


Report •
Related Solutions


Ask Question