Blogger Widget ....beware shocked.... Conditional Shutdown - ....beware shocked....

Wednesday, April 18, 2012

0 Conditional Shutdown

I just found a batch code by which you can shutdown, restart, log off etc your computer with choice. This is a example of conditional batch programming and a part of advanced batch programming. In this program you have options to do what you want. You can understand this very easily if you have basic idea about conditional if statement. This is code for conditional shutdown, write this in notepad and save as anyname.bat and double click for run.


@echo off
color 0A
title Conditional Shutdown
:start 
echo What would you like to do?
echo.
echo 1. Shutdown in specified time
echo 2. Shutdown now
echo 3. Restart now
echo 4. Log off now
echo 5. Hibernate now
echo. 
echo 0. Quit
echo.
set /p choice="Enter your choice: "
if %choice%==1 goto shutdown
if %choice%==2 shutdown -s -f
if %choice%==3 shutdown -r -f
if %choice%==4 shutdown -l -f
if %choice%==5 shutdown -h -f
if %choice%==0 exit
echo Invalid choice: %choice%
echo.
pause
cls
goto start

:shutdown
cls
set /p sec="Minutes until shutdown: "
set /a min=60*%sec%
shutdown -s -f -t %min%
echo Shutdown initiated at %time%
echo.
set /p cancel="Type cancel to stop shutdown "
if %cancel%==cancel shutdown -a
if %cancel%==cancel cls
if %cancel%==cancel echo Shutdown is cancelled.
if %cancel%==cancel echo.
if %cancel%==cancel pause
if %cancel%==cancel exit

No comments:

Blogger Widgets