Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I am new to batch file.I don't know about anything about batch file.

I want to learn batch file programming.
Please Give me some Good websites to learn batch file programming.

Thanks.
Posted

Just search the Web, you will find enough resources, but please keep in mind that most of them are from the DOS epoch, and with NT the command interpreter has grown considerably, even procedure calls with return to the caller were implemented.

So, you can get complete and fresh information only if you study the help provided by your system. This is not too easy, but there is a wonderful batch file which generates HTML help collected out of individual help pages. This batch file is very useful. Please execute it:

@ECHO OFF
IF "%OS%"=="Windows_NT" SETLOCAL DISABLEDELAYEDEXPANSION

:: Version number for this batch file
SET MyVer=1.40

:: Display "about"
ECHO.
ECHO AllHelp.bat,  Version %MyVer% for Windows NT 4 / 2000 / XP
ECHO Generate an HTML help file for "all" available commands
ECHO.
ECHO Note:
ECHO This batch file uses the redirected output of the HELP command to generate the
ECHO HTML file. Because some commands use "special" characters like ^&, ^<, and ^> in
ECHO their help screen, not all output is displayed correctly in the browser.
ECHO Known issues: skipped ^<space^> "tag" in CMD's special character list and skipped
ECHO \^<xyz and xyz\^> word position references in FINDSTR's output.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.
ECHO Improved white space handling by Johan Parlevliet
ECHO Further improvements for NT 4 by Ulf Lindb„ck
ECHO.
ECHO.
ECHO.

IF NOT "%OS%"=="Windows_NT" SET MyVer=
IF NOT "%OS%"=="Windows_NT" GOTO End

:: Store current code page and then set code page for European languages
FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%A) DO SET CHCP=%%B
CHCP 1252 >NUL 2>&1

:: Start writing HTML file
ECHO Writing HTML header . . .
> allhelp.htm ECHO ^<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"^>
>>allhelp.htm ECHO ^<HTML^>
>>allhelp.htm ECHO ^<HEAD^>
:: Read Windows version using VER command
FOR /F "tokens=1 delims=[" %%A IN ('VER') DO SET Ver=%%A
FOR /F "tokens=1* delims= " %%A IN ('ECHO.%Ver%') DO SET Ver=%%B
:: Read latest Service Pack from registry
CALL :GetSP
>>allhelp.htm ECHO ^<TITLE^>Help for all %Ver%%SP% commands^</TITLE^>
>>allhelp.htm ECHO ^<META NAME="generator" CONTENT="AllHelp.bat, Version %MyVer%, by Rob van der Woude"^>
>>allhelp.htm ECHO ^</HEAD^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<BODY^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A NAME="Top"^>^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<CENTER^>
>>allhelp.htm ECHO ^<H1^>%Ver%%SP% commands^</H1^>
FOR /F "tokens=* delims=" %%A IN ('VER') DO SET Ver=%%A
>>allhelp.htm ECHO ^<H3^>%Ver%^</H3^>
>>allhelp.htm ECHO ^</CENTER^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.

ECHO Creating command index table . . .
SET FirstCell=1
>>allhelp.htm ECHO ^<TABLE BORDER="0"^>
:: Skip 1 or 2 lines of HELP command's header
FOR /F "tokens=1 delims=[]" %%A IN ('HELP ^| FIND /N "."') DO IF %%A LEQ 2 SET Skip=+%%A
:: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
:: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
:: %Skip% skips 1 or 2 lines of HELP command's header
FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispLine "%%A"
>>allhelp.htm ECHO ^</TD^>^</TR^>
>>allhelp.htm ECHO ^</TABLE^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.

ECHO Writing help for each command:
:: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
:: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispFull "%%A"

ECHO Closing HTML file
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<DIV ALIGN="Center"^>
>>allhelp.htm ECHO ^<P^>This HTML file was generated by:^<BR^>
>>allhelp.htm ECHO ^<B^>AllHelp.bat^</B^>, Version %MyVer%
>>allhelp.htm ECHO for Windows NT^&nbsp;4^&nbsp;/^&nbsp;2000^&nbsp;/^&nbsp;XP^<BR^>
>>allhelp.htm ECHO Written by Rob van der Woude^<BR^>
>>allhelp.htm ECHO ^<A HREF="http://www.robvanderwoude.com"^>http://www.robvanderwoude.com^</A^>^</P^>
>>allhelp.htm ECHO ^</DIV^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^</BODY^>
>>allhelp.htm ECHO ^</HTML^>

ECHO.
ECHO An HTML help file "allhelp.htm" has been created and stored in the current
ECHO directory.
ECHO.
ECHO Now starting display of "allhelp.htm" . . .
START "AllHelp" allhelp.htm

:: End of main batch program
CHCP %CHCP% >NUL 2>&1
ENDLOCAL
GOTO:EOF


:: Subroutines


:DispLine
SET Line=%1
SET Line=%Line:(=^(%
SET Line=%Line:)=^)%
SET Line=%Line:"=%
SET Command=%Line:~0,8%
SET Command=%Command: =%
IF DEFINED Command CALL :DispCmdLine %Command%
FOR /F "tokens=1* delims= " %%a IN ('ECHO.%*') DO SET Descr=%%b
SET Descr=%Descr:"=%
>>allhelp.htm ECHO.%Descr%
GOTO:EOF


:DispCmdLine
IF "%FirstCell%"=="0" IF DEFINED Command (>>allhelp.htm ECHO ^</TD^>^</TR^>)
SET Command=%1
IF DEFINED Command (>>allhelp.htm ECHO ^<TR^>^<TH ALIGN="left" VALIGN="top"^>^<A HREF="#%Command%"^>%Command%^</A^>^</TH^>^<TD^>^&nbsp;^&nbsp;^&nbsp;^</TD^>^<TD^>)
SET FirstCell=0
SET Command=
GOTO:EOF


:DispFull
SET Line=%1
SET Command=%Line:~1,8%
SET Command=%Command: =%
IF DEFINED Command CALL :WriteFull %Command%
SET Command=
GOTO:EOF


:GetSP
SET SP=
:: Export registry tree to temporary file
START /WAIT REGEDIT.EXE /E "%Temp%.\%~n0.dat" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
IF NOT EXIST "%Temp%.\%~n0.dat" GOTO:EOF
:: Read value of "CSDVersion" from temporary file
FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\%~n0.dat" ^| FIND /I "CSDVersion"') DO SET SP=%%~A
:: Check if value is valid
ECHO.%SP% | FIND /I "Service Pack" >NUL
IF ERRORLEVEL 1 SET SP=
DEL "%Temp%.\%~n0.dat"
:: Use a shorter notation
IF DEFINED SP SET SP=%SP:Service Pack=SP%
GOTO:EOF


:WriteFull
ECHO.  %1 . . .
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A NAME="%~1"^>^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<H2^>%1^</H2^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<PRE^>
>>allhelp.htm HELP %1
>>allhelp.htm ECHO ^</PRE^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A HREF="#Top"^>Back to the top of this page^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.
GOTO:EOF

:End


Unfortunately, I can not remember the source where I got it, but you can see that it was written by Rob van der Woude, http://www.robvanderwoude.com[^] and Johan Parlevliet.

I'm very grateful to them.

On the Web page referenced above, you will find reference to very useful pages devoted to batch programming.

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 4-Jun-12 10:09am    
A 5 as usual :-D
Sergey Alexandrovich Kryukov 4-Jun-12 12:47pm    
Thank you, Espen.
--SA
Refer this
1)http://aumha.org/a/batches.php[^]
2)http://dos.rsvs.net/DOSPAGE/BATCHCOM.HTM[^]
3)http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true[^]

Here is a sample batch file for you

Open Notepad and type the following code
====================================
Title "Welcome to Batch programming"
color a
prompt :
cls
echo Sample code for Batch program
calc 
mspaint
notepad
winver
pause 
echo " Bye Bye "
pause 
exit
====================================


now save the file as sample.bat in your local machine and run the file.....!!!

Hope this will be helpful
 
Share this answer
 
v2
Hi,

Interesting Question, long back i have worked with these batch files, even i don't know about the batch programming, here is the link which is help me a lot for DOS batch syntaxs
Here[^]

Hope this will help you, good luck

Thanks
--RA
 
Share this answer
 
Your first step is to learn about google :)

Link[^]
 
Share this answer
 
v2
Comments
jim lahey 4-Jun-12 5:18am    
wow Rajesh, you look young for a senior developer! what's your secret if I may ask? :)
thatraja 4-Jun-12 16:48pm    
That's his kid.
you find batch file programming books on google
now i am giving a sample code link i think it will help you Look[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900