Here's the specs for a utility program that I wrote in 1994 to insert into batchfiles to do things that you can't normally do in a batchfile, thus making them more "robust":
Code:
!BAT Multiple Utility Program for Batch Files
-------------------------------------------------------
Usage: !BAT /OPTION [specs and switches for OPTION]
Invoke !BAT program within a batchfile.
The following is a list of the available OPTIONS:
* BAK - Copy specified file to a backup file.
- Syntax: !BAT /BAK [d:][path][Filename[.ext]] [/EXT=]
- Default file extension is BAK.
- If /EXT= specified: provide max 3-letter file extension.
- Example: Use in batchfile to call MSDOS EDIT program,
which gives you no backup file.
* CAPSOFF - Sets Caps Lock OFF.
- Syntax: !BAT /CAPSOFF
* CAPSON - Sets Caps Lock ON.
- Syntax: !BAT /CAPSON
* DISKSIZE - Determines the size of the specified drive.
- Normal usage is to determine a diskette's size.
- Syntax: !BAT /DISKSIZE d:
where d: is the drive.
- Return Codes:
* Errorlevel 0 = Disk size less than 360 KB.
* Errorlevel 1 = Disk size is 360 KB.
* Errorlevel 2 = Disk size is 730 KB.
* Errorlevel 3 = Disk size is 1.2 MB.
* Errorlevel 4 = Disk size is 1.4 MB.
* Errorlevel 5 = Disk size is 2.8 MB.
* Errorlevel 6 = Disk size is 2.9 MB or greater.
* Errorlevel 255 = Have issued an error message.
DOSENGLISH - Tests language of DOS operating system, returns:
errorlevel = 0 if DOS is in English.
errorlevel = 1 if DOS is NOT in English.
- Syntax: !BAT /DOSENGLISH
* EXIST - Tests existence of specified Spec, and returns:
errorlevel = 0 if Spec exists.
errorlevel = 1 if Spec does not exist.
- Spec can be Drive and/or Path and/or Filename, w/wildcards.
- Syntax: !BAT /EXIST [d:][path][FileSpec[.ext]] [/D] [/NZL]
- /D means test if Spec exists as a directory or
subdirectory only.
- /NZL (Not Zero Length) means test a Spec OF A SINGLE
FILENAME to see if it exists AND is not a zero length file.
- (/D and /NZL are mutually exclusive)."
* KILLFILE - Kill (delete) single file regardless of attribute.
- Syntax: !BAT /KILLFILE [d:][path]Filename[.ext]
* LOCKUP - Locks the PC forcing power off/on.
- Syntax: !BAT /LOCKUP
* MAKEDIR - Purpose: to create a directory, testing for errors.
- Syntax: !BAT /MAKEDIR [d:][path]DirectoryName
- Scope:
* DirectoryName is first validated (see below).
* If DirectoryName already exists as a directory,
then the program just exits.
* However, if it exists as a file, then the conflicting
file is renamed with a file-extension of .!!!.
Then the desired directory is created. (Note: I had to
make a choice here. Your batch file is creating a dir
for its use, and a duplicate filename in the parent dir
probably does not matter to a production batch file,
and it certainly did not exist when you tested.)
* If DirectoryName does not exist, it is created. This is
the normal case.
* Normal termination issues an errorlevel 0.
* The following errors are detected, producing a corres-
ponding error message on the screen with a pause, and
an errorlevel 1 upon exit:
- Invalid DirectoryName according to DOS rules.
- Wildcards in DirectoryName.
- Invalid, not ready, or write protected drive.
- A parent directory, specified in [path] which
does not exist.
* Hint: Substitute MD in your batch files with
!BAT /MAKEDIR followed by IF ERRORLEVEL 1.
* MSG - Reformats and displays Message-Text, and waits for a key.
- Syntax: !BAT /MSG Message-Text [/YESNO] [/KEYS=] [/color]
- Optional Control Characters within Message-Text:
~ means toggle the alphabetic case, first upper to lower.
\\ means end-of-line, go to next line of message.
- If /YESNO specified:
* Response key can only be Y,S, or N.
* If response is Y or S, errorlevel=0. If N, errorlevel=1.
* (S is to accomodate the Spanish affirmative SI.)
- If /KEYS= specified:
* Response is related to number of character keys
that follow.
* The errorlevel number is the position of each
character key.
* NOTE: /KEYS= will override /YESNO if also specified.
- Colors can be specified for the prompt by appending
a / and the name of one of the following colors:
blue,green,cyan,red,magenta,brown,gray.
- Example:
!BAT /MSG M~ASTER FILE HAS BEEN UPDATED.\\~D~O YOU WANT TO
GENERATE A BACKUP?/YESNO
IF ERRORLEVEL 1 GOTO NOBACKUP
GOTO YESBACKUP
Above will produce a message screen with following text
centered in a default red box:
Master file has been updated.
Do you want to generate a backup?
...Press (Y/N)...
* NUMOFF - Sets Num Lock OFF.
- Syntax: !BAT /NUMOFF
* NUMON - Sets Num Lock ON.
- Syntax: !BAT /NUMON
* RETURN1 - Saves the current directory, so you can get back to it.
- Syntax: !BAT /RETURN1
- When you execute the RETURN1 it determines the current
directory's drive and full path, and creates a batch file
called !RETURN2.BAT into the root directory of drive c:,
which, when executed, will put you back on the original
drive and directory.
- So, you issue !BAT /RETURN1 in your batch file at the
point you want to save the current drive/directory,
then later issue a CALL C:\!RETURN2 to restore it.
* SOUND - Produces 1 of 10 different sound patterns.
- Syntax: !BAT /SOUND [n]
where the optional n is the sound number 1-9,
and no number emits a standard beep.
* TESTDRIVE - Tests if the specified drive is ready.
- Syntax: !BAT /TESTDRIVE d: [/W]
where d: is the drive.
/W option means also test if ready for writing;
i.e., in the case of diskettes, not write protected.
- If drive is ready, ERRORLEVEL 0 is returned.
- If drive is not ready, ERRORLEVEL 1 is returned.
* TESTLP - Tests if the line printer is ready.
- Syntax: !BAT /TESTLP [n]
where the optional n is the LPT number 1-3. Default is 1.
if line printer is ready, ERRORLEVEL 0 is returned.
if line printer is not ready, ERRORLEVEL 1 is returned.
* WARMBOOT - Performs a "warm" boot of the PC,
as if the Ctrl-Alt-Del keys had been pressed.
- Syntax: !BAT /WARMBOOT
* YESNO - Prints a prompt and checks response char.
- Syntax: !BAT /YESNO [prompt string][/KEYS=][/color]
- The default prompt is : do you wish to continue (Y/N).
If response is Y or S, errorlevel=0. If N, errorlevel=1.
(S is to accomodate the Spanish affirmative SI.)
- If only the prompt string is provided, the responses
are Y or S, and N as above.
- If prompt string and /KEYS=, the responses are related
to the number of keys specified, with the errorlevel number
equal to the relative position of each key.
- Colors can be specified for the prompt by appending
a / and the name of one of the following colors:
blue,green,cyan,red,magenta,brown,gray.
- Example:
!BAT /YESNO WHICH PRINTER? (1/2/3)/KEYS=123/RED
IF ERRORLEVEL 3 GOTO PRN3
IF ERRORLEVEL 2 GOTO PRN2
...(logic for prn1)...
...(since keys were 123, you only get errorlevels 1-3)