Sign in with
Sign up | Sign in
Your question

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

Last response: in Windows XP
Share
November 6, 2010 6:51:12 PM

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 !
November 6, 2010 6:53:56 PM

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.
November 6, 2010 11:18:38 PM




Maybe the XP Shutdown.exe will do it for you.
Full explanation of it's use is
HERE.
Related resources
November 7, 2010 8:20:29 AM

tigsounds said:
Maybe the XP Shutdown.exe will do it for you.
Full explanation of it's use is
HERE.


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!
November 7, 2010 2:30:09 PM

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)
November 8, 2010 1:15:59 PM

tigsounds said:
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!
June 9, 2011 4:28:12 AM

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
!