Auto shutdown

Force shutdown Windows can simply execute command

shutdown -f -s -t 0

You can enhance the script by create a schedule job like auto shutdown your pc at mid night 12am. Normally I have a habit listen to radio to sleep, just like a baby arh? haha.. now the radio became online. Many online radio are offer listen online through your browser now, so you also can create a schedule job to kill your browser to prevent the radio turn on until next day which will harm to your ear even though you asleep.

taskill /IM firefox.exe

But what about if during your shutdown script you want to do some checking? Like maybe you don’t want really shutdown pc if the downloading task still running? So a more complex script is required in this case. The script below is call the row count on tasklist if found the specified exe name, then put a stop on close command.

@echo off
setlocal enableextensions
set counter=0

rem check bitcomet is running or not
for /f "tokens=*" %%a in (
'tasklist ^| find /C "BitComet.exe"'
) do (
set counta=%%a
)

rem check JDownloader is running or not
for /f "tokens=*" %%a in (
'tasklist ^| find /C "javaw.exe"'
) do (
set countb=%%a
)

rem echo %counta%
rem echo %countb%
set /A counter=%counta% + %countb%
rem echo %counter%
if %counter% equ 0 goto :CLOSE
goto :EXIT
endlocal

:CLOSE
echo c:\windows\system32\shutdown -f -s -t 0

:EXIT
Advertisements

One thought on “Auto shutdown

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s