How to make the pc turn off when some app is closed with a batch file

rickzor

Distinguished
Feb 11, 2007
506
0
18,990
Hi there!.

I'm trying to create a batch file that shuts the computer down when a app that the batch itself has started, is turned off.

Actually, i want it to start that app with some delay, but so far what i was able to acomplish was the batch to start the app with delay with the code as follows:

@Echo Off
PING 1.1.1.1 -n 1 -w 8000 >NUL
Start ""- "C:\Programas\TVR\TVR\tvr.exe"
exit

It start's the code with 8 seconds of delay, but now i want it to turn the computer off when the tvr.exe is closed manually.

I found that the "WMIC OS Where Primary=TRUE Call Shutdown" command shuts the computer down, but i can't make the rest of the code to work with it.
Btw i'm using windows xp.

Help is appreciated. Thanks in advance !
 
Actually the title should be "How to make the pc turn off with a batch file when some app is closed manually" but it seems that TOMSHARDWARE doesn't allow me to edit my own thread.
 


Hi there and thanks for awnsering.

I'm sorry and i am still a newb, and everything i'm learning is through reading on the net.

Still with the link you gave me i could not figure how to make Windows shutdown when a specified executable is terminated!
 
Make the last step in the batch file read:

shutdown -s

It will put a box on the screen saying the system is going to shut down in 30 seconds, and save your work, (and then computer turns off). You have about 15 seconds to abort the shutdown (shutdown -a)
 


That does shutdown the computer, but it wouldn't correlate with the ".exe" i needed! I googled and tried to learn a bit and i already got it to work!

Here goes:

@Echo Off
sleep 8
Start C:\Programas\TVR\TVR\tvr.exe >temp.log
:check
sleep 1
del temp.log
if exist c:\temp.log goto :check
if not exist c:\temp.log goto shutdown
:shutdown
WMIC OS Where Primary=TRUE Call Shutdown
exit


Basicly what it does is to start the ".exe" with a delay of 8 seconds generating a temporary log that the routine tries to delete when possible. When the ".exe" is terminated manually the routine manages to finally delete the log file successfully, making the computer shutdown!

I though it would be nice post this because i did research a lot and who know, it might be useful for someone else.

Thank you anyway!
 
thaaanks you really helped me at this field but i need to know what if i want to put application on a usb flash memory and made my computer boot from it and read the application and when i eject the usb the computer shutsdown