Jump to content

Windows Task Scheduler: Program Dependency

rustikles
Go to solution Solved by fizzlesticks,

As far as I know there is no way to not start program A if B isn't running, the closest you could get is killing A as soon as possible.
Here's a batch file that can be started from task scheduler on system startup and be run in the background that will only let Chrome run if Firefox is running.

@[member=Echo] off:start	set aRunning=0	set bRunning=0	tasklist /FI "IMAGENAME eq firefox.exe" 2>NUL | find /I /N "firefox.exe">NUL	if "%ERRORLEVEL%"=="0" set aRunning=1	tasklist /FI "IMAGENAME eq chrome.exe" 2>NUL | find /I /N "chrome.exe">NUL	if "%ERRORLEVEL%"=="0" set bRunning=1		if %bRunning% == 0 goto endloop	if %aRunning% == 1 goto endloop	taskkill /im chrome.exe	echo "Killed chrome.exe"	:endloop	timeout /t 5 /nobreak >NUL	goto start

edit: And when I say only let Chrome run if Firefox is running, I mean Chrome will always start then die 0-5 seconds later if Firefox isn't running.
 

I'm looking for a way (with win7 task scheduler or otherwise) to create a dependency of one program on another to be active.

 

i.e: in order for program A to start, program B must already be running. Also, program A would be forced quit if program B is not detected as running at a set interval. 

 

I could just write a batch file for each action (startup and shutdown), but I'd like it to be more of a conditional that runs in the background so I don't have to worry about the way I activated the program (shortcut, search, etc). Thanks for the help!

CPU: i5 4670k • Cooler: Corsair H100i • Motherboard: MSI Z87 MPOWER • RAM: Crucial Ballistix Elite 2x 8GB • Storage: Samsung 840 250GB SSD, 2x WD Red 3TB • GPU: EVGA GTX 780 3GB • PSU: Corsair RM750W • Case: Corsair 750D • Mouse: Razer Naga 2012 (I actually use the thing for productivity/media buttons) • Keyboard: Ducky Shine 3 w/ Browns - Green LED • Monitor: Asus PB278Q 27" 2560 x 1440, ASUS PB238Q 23" 1920x1080 • Lighting: 2m NZXT Sleeved Blue LED Strip • pcpartpicker.com/p/3cHfZ

 

Link to comment
Share on other sites

Link to post
Share on other sites

As far as I know there is no way to not start program A if B isn't running, the closest you could get is killing A as soon as possible.
Here's a batch file that can be started from task scheduler on system startup and be run in the background that will only let Chrome run if Firefox is running.

@[member=Echo] off:start	set aRunning=0	set bRunning=0	tasklist /FI "IMAGENAME eq firefox.exe" 2>NUL | find /I /N "firefox.exe">NUL	if "%ERRORLEVEL%"=="0" set aRunning=1	tasklist /FI "IMAGENAME eq chrome.exe" 2>NUL | find /I /N "chrome.exe">NUL	if "%ERRORLEVEL%"=="0" set bRunning=1		if %bRunning% == 0 goto endloop	if %aRunning% == 1 goto endloop	taskkill /im chrome.exe	echo "Killed chrome.exe"	:endloop	timeout /t 5 /nobreak >NUL	goto start

edit: And when I say only let Chrome run if Firefox is running, I mean Chrome will always start then die 0-5 seconds later if Firefox isn't running.
 

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

That's about the route I figured I would have to go. Thanks  :D.

CPU: i5 4670k • Cooler: Corsair H100i • Motherboard: MSI Z87 MPOWER • RAM: Crucial Ballistix Elite 2x 8GB • Storage: Samsung 840 250GB SSD, 2x WD Red 3TB • GPU: EVGA GTX 780 3GB • PSU: Corsair RM750W • Case: Corsair 750D • Mouse: Razer Naga 2012 (I actually use the thing for productivity/media buttons) • Keyboard: Ducky Shine 3 w/ Browns - Green LED • Monitor: Asus PB278Q 27" 2560 x 1440, ASUS PB238Q 23" 1920x1080 • Lighting: 2m NZXT Sleeved Blue LED Strip • pcpartpicker.com/p/3cHfZ

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×