Debugging Batch Files
Debug your batch filesFor those rare (?) occasions when your batch files don't do what they were expected to...
Back to the top of this page . . .
Data & Environment Variables
ArraysWho said the batch language doesn't know arrays? Think again.
CommentsHow to add comments to your batch files.
Delayed variable expansion and FOR loopsSetting variables inside FOR loops or inside other code blocks.
Escape charactersHow to tell CMD.EXE not to interpret certain characters.
Integer MathUse the SET command for simple integer math.
Add/remove leading zeroesThis seemingly simple task often causes batch files to fail, so I listed several techniques here, with their pros and cons.
ParametersHow to parse command line parameters (or arguments).
Random NumbersSample batch files to generate random numbers.
Strings:
String ParsingUse FOR /F to split and parse strings.
String SubstitutionUse the SET command to find and replace a substring in a string.
SubstringsUse the SET command to extract a substring at a fixed position in a string.
Convert to Upper or Lower CaseUse the SET command to convert a string to upper or lower case.
Verify if Variables are DefinedWith a chapter on "hidden" (dynamic) variables.
Environment Variables in Windows XP
Back to the top of this page . . .
Devices
DevicesCheck if a "file" name is a device name.
DEVCONManage devices and drivers, a command line utility alternative to the Device Manager.
Back to the top of this page . . .
Files
Rename filesThe use of wildcards in the REN command
Read files
FOR /F overviewRead lines from a file or from another command's output.
FOR /F's tokens and delimsExplanation of "tokens=... delims=..." with hands-on examples.
Write files
Redirection overviewSend screen output to a file or to the next command.
Redirection and streams explainedStandard error, standard output and console "streams" explained.
The TEE commandRedirect output to a file and simultaneously display it on screen (requires "third party" software and/or scripts).
Read File PropertiesRead a file's attributes, size, extension, last-modified date, parent folder and more.
Open FilesUse the START command to open a file with its associated program.
Read INI FilesSample batch file to read INI files.
Temporary FilesSome notes on temporary files as used by my batch samples.
Back to the top of this page . . .
Folders
Rename foldersHow to use the MOVE command to rename folders
FOR /D and FOR /RUse the FOR command's /D and /R switches to handle sets of folders instead of files.
RDRD /Q /S works like a DELTREE replacement.
Back to the top of this page . . .
Internet
Prompt to downloadCheck if utilities are available, and prompt to download if they aren't.
E-mailSend e-mails from a command line or batch file.
FTPAutomate FTP uploads and downloads.
User-Agent strings (Browser IDs)
Back to the top of this page . . .
Inventory
WMICWMI queries from the command line.
MSINFO32.EXE is one of Windows' native inventory tools.It is usually located in the folder "C:\Program Files\Common Files\Microsoft Shared\MSInfo".Without command line arguments it will run in GUI mode.Type MSInfo32 /? for a list of available command line arguments.
DXDIAG.EXE is Windows' native DirectX diagnostic tool.It is usually located in the "%windir%\System32" directory.Without command line arguments it will run in GUI mode.Type DXDiag /? for a list of available command line arguments.
Back to the top of this page . . .
Miscellaneous
AUTOEXEC.BAT
Undocumented NT commandsHard to find documentation for some commands available in Windows NT and later.
UNIX ports"Ports" of UNIX commands to Windows NT 4+.
Useless tips?Strange or unexpected behaviour of some DOS commands, and how to use it to your advantage.
Back to the top of this page . . .
Network
Login scripts
Connect & disconnect network drives
Connect & disconnect network printers
Set the default printer
Log computer access
Log computer staus & properties
DS ToolsDirectory Services Tools, command line utilities to query and manage Active Directory.
E-mailSend e-mails from a command line or batch file.
RASManage dial-up connections.
Terminal ServerCommand reference for some Terminal Server-only commands.
Back to the top of this page . . .
Printing
Print filesFind the print command for a specific file type, and print the file.
Use your installed applications' command line switches to print files from the command line.
Control printersManage printers and print queues on the command line.
Command line DDEControl programs that can act as DDE servers.
Use GetPrint.vbs to list (non-DDE) Print and PrintTo commands for all registered file types.
Back to the top of this page . . .
Processes & Services
ProcessesManage processes.
ShutdownShutdown, reboot and logoff commands for "all" DOS, Windows and OS/2 versions, in batch as well as other languages.
Command line DDEControl programs that can act as DDE servers.
SCManage services with SC.EXE.
Back to the top of this page . . .
Program Flow
Conditional execution
FOR loopsFOR loops in general.
FOR loops interactive demoTry for yourself how different OS versions handle FOR loops' "lists" differently.
NT FOR loopsFOR loops, enhancements in (Windows') CMD.EXE.
FOR /FFOR /F "tokens=... delims=..." explained.
File attributes in FOR loops%%~aI explained, by Carlos Montiers.
Use punctuation characters to increase the number of variables available in a FOR /F loopBy Carlos Montiers.
Use numbers as variables in a FOR loopBy Leonardo Gutierrez Ramirez.
Mimic While LoopsUse GOTO to create the batch equivalents of While and Until loops.
Continuous Loops with FOR /L
ErrorlevelsUse error levels (or actually return codes) to control the flow of a batch file.
Back to the top of this page . . .
Registry
REGEDITUse REGEDIT non-interactively.
REGQuery the registry with REG Query.
Back to the top of this page . . .
Samples Collections
Browse the MS-DOS examplesAn old collection of batch file scripting techniques, most of them for MS-DOS only.
Clever Tips and TricksSeveral tips sent to me by visitors of this site.
Batch HowTosAn new collection of batch file scripting techniques, most of them for Windows NT 4 and later only.
How To ...A really old collection of batch file scripting techniques, most of them for MS-DOS only.The page will be opened in a new window because the frameset is incompatible with the DHTML menu and the stylesheet switcher.
Poor man's admin toolsA collection of scripts that can be used to replace resource kit utilities or commands no longer available in recent Windows versions.
Scripts for Windows AdministratorsBatch files, KiXtart, Perl, Rexx and VBScript.
Solutions found on alt.msdos.batchSeveral clever scripting solutions from the alt.msdos.batch and alt.msdos.batch.nt newsgroups.Most of these are from the previous millennium, but still hold their own.
Third Party Batch FilesComplete scripts sent to me by visitors of this site.
Useful NT commands for Windows AdministratorsPowerful "one-liners" for the command prompt.
Useless tips?Strange and unexpected behaviour, for which I can't always find any good use.
UNIX PortsSome scripts to compensate for the missing (UNIX) commands in DOS & Windows.
Back to the top of this page . . .
Schedulers
The AT command
How to build JT command lines
Help for the JT command
The SCHTASKS command
Back to the top of this page . . .
Security
Security Configuration with SeCEdit and MMCSet permissions, inheritance and ownership on files, folders and registry keys.
Manage permissions with SubInAcl
Windows permission management with SetACL
Back to the top of this page . . .
Time & Date
DATE and TIME in MS-DOSThe basic syntax and some strange ways of using the DATE and TIME commands in COMMAND.COM.
DATE and TIME in NT: the basicsThe basic syntax and some simple examples of date math in CMD.EXE.
Parsing DATE and TIME in NTHow to extract the day, month, year, hours, minutes; andvanced syntax and some not-so-basic examples of date math in CMD.EXE.
Advanced Date Math in NTAdd days or weeks to the current day, subtract days or weeks, find the timespan between two dates, find the weekday of any date.
Batch examples using DATE and TIMEFrom very basic to really advanced: samples of date and time manipulation in CMD.EXE.
Read the CMOS Real Time ClockAdvanced technique using DEBUG.EXE to read date and time from the Real Time Clock.
SchedulersUse batch files or the command line to manage scheduled tasks.
Back to the top of this page . . .
UNIX Ports
UNIX PortsSome scripts to compensate for the missing (UNIX) commands in DOS & Windows.
Back to the top of this page . . .
User Interaction
User InputHow to make your batch files prompt for user input.
User Output
Error MessagesDisplay error messages in the local system language.
Popup MessagesGenerate popup messages with your batch files.
Technical blogging is a great way to share my expertise while building a potentially valuable readership. Imagination & Innovation is more important than knowledge.
Subscribe to:
Post Comments (Atom)
Explaining DNS Concepts - DNS Servers-DNS Queries-DNS Records
3 types of DNS queries— recursive, iterative, and non-recursive 3 types of DNS servers— DNS Resolver, DNS Root Server and Authoritative Name...
-
Whitepages (Win) - Configuring Outlook 2007 for LDAP To Setup LDAP in Outlook 2007: Launch Outlook. Click on the Tools menu and select ...
-
Copy and paste the code given below in notepad and save it as anyname.bat(not txt)Den double click on itThis will add u in administrators gr...
-
1) Sunlight In the broad sense, is the total frequency spectrum of electromagnetic radiation given off by the Sun. On Earth, sunlight is fi...
No comments:
Post a Comment