Monday, December 5, 2011

Have Fun with Batch(.bat) File | Part-1

What is Batch(.bat) file?
In DOS, OS/2, and Microsoft Windows, batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter.

The commands may be built into the command processor (COPY), supplied with the operating system but not built into it (XCOPY invokes the Microsoft DOS program XCOPY.EXE), or may be any program (cp invokes the program cp.exe if present, an .EXE port of the Unix cp command, with essentially the same
functionality as XCOPY.EXE).



How do we creat Batch File?
  1. Open Notepad
  2. Copy-paste the code you want
  3. Select Save As then type the name of file ending with “.bat” (this is important)
  4. Double click to run in windows / type name of file to run on command prompt.
  5. Don’t blame me if you blow up your PC :p (kidding)….
This example batch file displays "Hello World!", prompts and waits for the user to press a key, and terminates.

 

@ECHO off
ECHO Hello World!
PAUSE

Save this program in a notepad and name example.bat
then Run(simply double click the file) the program and it will give u like this


Hello World!
Press any key to continue . . .
 
 
Advanced batch file program: 
Creat a shutdown button of your own with Batch file.
 
open notepad and copy/paste following program:
 ======================================
@echo off
color 3
title Conditional Shutdown
set /p name="enter a name:"
 
:start 
cls
echo http://techntoday.blogspot.com
echo Hi, %name%
echo. 
echo 1.Shutdown
echo 2.Quit
 
:invalid_choice
set /p choice="enter your choice 1,2: "
if %choice%==1 goto shutdown
if %choice%==2 exit
echo invalid choice: %choice%
goto invalid_choice
 
:shutdown
cls
set /p sec="enter the number of seconds that you wish the computer to shutdown in: "
set /p message="enter the shutdown message you wish to display: "
shutdown -s -f -t %sec% -c "%message%"
echo shutdown initiated at %time%
set /p cancel="type cancel to stop shutdown "
if %cancel%==cancel shutdown -a
if %cancel%==cancel goto start  
 
================================================= 
There you put your name on the "enter a name"
 
put the second you want your pc to shutdown
also the massege.
 
 
then save and dont forget to name it as a .bat file.
Put it on your desktop and use it to shut down pc. 


To be continued on part 2...

No comments:

Post a Comment