Batch File Library

Batch Files, Run In a DOS Window,
Offer Exceptional Programming Power
In a Very Accessible Package.

   DOS was Microsoft's original operating system. An important part of DOS was the ability to customize it with simple scripts called "Batch Files". These programs, mostly small but some quite complex, could be written from any DOS prompt.
   Although Windows brings a new world of convenience and important strengths, these old fashioned Batch files can still be an important tool for tuning and maintaining a computer system.

   A batch file is a set of instructions in a plain text file, with an extension of ".bat". There is nothing special about the files themselves, which can be edited with any word processor. Right-clicking on a batch file in Windows will show the menu option of Edit, which should open the file into Notepad. Batch file programming is well documented in books and many excellent web sites, along with utilities such as help.com which may be installed on your machine. (Type "help" and return at any MS-DOS prompt to see if help.com is installed.)
   In Windows today, the Autoexec.bat file (found in the C:\ root directory) still has an important role in startup actions. Other batch files or DOS utilities can be run at any DOS prompt because they are stored in the C:\Windows\Command directory, source of DOS program files and the easiest place to keep system-wide batch files.

Batch File Overview: PIF Files

Backupme.bat-Duplicate Folders

Registry Backup and Restore
Setup_sp.bat - Control your boot.

Makeboot.bat-Create Startup Disks
 
   

Installing The Batch Files

   Below are four batch file utilities. Each is packaged as a compressed archive in an .Exe executable program for convenient downloads. Run each EXE file to extract the files, which will default to their own folder with a descriptive name on the root level of the C: drive. (IE: C:\Setup_sp.)
   Each extracted folder will contain an install program (Install). There will also be a text document with an appropriate name, which contains information about each batch routine. The folder will also include any required bat and PIF files. A shortcut for C:\Windows\Command will appear in each of these installation folders, for convenience.
   To run an installed Batch file, look for the shortcuts in menu item "Batch Files", installed in the Start Menu, under Programs. This is the cleanest way to run these files, as this uses the configured shortcuts. (PIF files.) They can also be run from any DOS command prompt, by typing the name of the batch file. (The ".bat" at the end is optional.) Or the Run... option from the Start Menu can be used. Select "Run...", type the name of the batch file, and press the return key.

Batch File Overview: PIF Files

   Batch files are not very user friendly. When a user clicks twice on a batch file to run it, an ugly black DOS window will appear. This window will stay up when the routine has completed, with the cryptic word "Finished" in the title bar, or will complain that you may damage something if you try to close it before the routine is over. This does not make for a great deal of happiness when using batch files for system maintenance. The best way to avoid problems with Batch files is to never run them- directly. Instead, run a batch file from their Shortcut, known as a PIF file. ("Program Information File", a relic from Windows 3).
   The easiest way to make a PIF file is to hold the right-hand mouse button down and move the file slightly (Right drag the file) within the same directory- a menu will appear with "Create Shortcut" as an option. Select this. Your PIF file is now created. It will have the colorful MS-DOS icon. The name will be the same as the original batch file that it was created from. This name can be changed to anything that pleases you.
   To edit the PIF file and make it useful, call up the Properties for this shortcut. This will open the PIF Editor, not the usual Shortcut properties screen. You may either Right-Click on the PIF file and choose "Properties" from the menu, or select the file with a single click and use the ALT-ENTER Key combination.
   Below is shown a sample PIF screen for the Backupme.bat file. Change to the "Program" Tab.
   The icon has been changed with the "Change Icon" button in the bottom right to an Umbrella- More indicative of a backup routine, perhaps.
   The Cmd Line, which is the same as typing an instruction into a DOS window, has been modified to include two parameters. ("C:\My Documents", "C:\My Documents BU"). Any path information before the name of the batch file was also removed, for clarity's sake. If this batch file is stored in the C:\Windows\Command folder, the path information is not necessary. If, however, it is stored elsewhere on the disk, the path information should be left in place.

   There is no working directory listed, or required for this routine. The Run window is set to run in a Maximized DOS window, that will try to fill the screen. (And gets your attention.) Other options are Normal (Quite small, actually, on a large screen monitor), and Minimized (so you will not realized the routine is running.) The Screen tab across the top of the PIF Editor allows a real Full Screen option, if these choices are not sufficient.
   The "Close on exit" box is checked. This is important! It is the best way to get the annoying DOS screen off your monitor when the routine has completed running. This box should normally be checked. (The default is without a check mark.)

Registry Backup and Restore:
|RegSAVE.bat, RegREST.bat
(DOWNLOAD. Tip- Hold SHIFT key down, and click link.)

These are two batch files. RegSAVE.bat copies the critical registry files System.dat and User.dat to the C:\ Root as System.dak and User.dak. The companion file is RegREST.bat, a batch file that will restore the *.dak backup files to the Registry. There is an accompanying PIF file for RegSAVE.bat.
   Please note that it is important to backup your registry often, especially before installing any unusual software. Also be aware that restoring a registry can correct problems, but may cause programs installed since the last backup to no longer work properly, or run at all. This backup is for times when the system has utterly crashed, and cannot be made workable again without a restoration of the registry.
   The best way to RESTORE a registry is to first have a backup of a working copy of one. (Use RegSAVE.bat to make a backup of the critical Registry files.) If a backup exists, boot the computer either with a floppy disk (See MakeBoot.bat below for a way to make a floppy disk), or use the F8 key while the system starts to get at the Startup Menu. (Press F8 just before the system says "Loading Windows 9x.) Use this menu to boot into MS DOS Safe Mode. Go to the C:\Windows\Command directory by typing:

C: [and Enter, to be on the C: drive]
CD C:\Windows\Command [and Enter.]
RegREST.bat [and Enter, to restore the Registry.]

   Did you know that Windows takes a backup of the Registry files each time it starts up? It uses these files to recover in case of a crash. There is, unfortunately, only one copy and this it is often overwritten with a damaged registry before Windows recognizes that a problem has occurred. Backup your registry often, to avoid serious problems. You may also want to make copies of the *.dak files that the RegSAVE.Bat routine produces onto another disk, in case the copy in the C:\ directory itself is somehow damaged. These files are typically much too large to fit on a floppy, even with the help of a compression utility such as WinZip. It would still be a good idea to make regular backups of these *.dak files. This could be as simple as an extra copy stashed somewhere on your hard disk.

Makeboot.bat (DOWNLOAD. Tip- Hold SHIFT key down, and click link.)
The Windows Control Panel item "Add-Remove Programs", has a tab for a Startup Disk. Selecting this tab, and inserting a blank (or soon-to-be blank) floppy will produce an DOS startup disk oriented to the efficient running of Windows Setup. This is a good thing! You should have on-hand a startup disk such as this one. (This is also the Startup Disk that Windows Setup invites you to make when the software is first installed.)
   However, many times we may not want to run Windows Setup, but are still interested in booting the machine with a floppy for maintenance purposes. The Makeboot.bat file, placed in C:\Windows\Command, makes a quality startup disk that can be used to perform a large number of standard system maintenance tasks. This is also a "personalized" version of a Startup Disk, and can be adapted to meet a special need.
   To use Makeboot.bat, look for the installed PIF shortcut in the Start Menu, under Programs, under Batch Files. Or it can be run directly from DOS. Open RUN from the Start Menu. Enter "makeboot" and press Enter. The program will run, and create the boot disk from a blank floppy placed in the drive. It will first ask if the floppy is to be formatted (not a bad idea, even with a "factory format" floppy). If not, the contents of the disk will be erased anyway before the routine continues.
   When completed, the floppy will be ready to start your machine with the version of DOS that is currently installed on it. (This version varies between Windows 95, 98, NT, and 2000- and it makes a BIG difference!) The disk will also contain handy utilities, such as:
Fdisk.exe, Format.com, Sys.com, Debug.exe, Xcopy.exe, Xcopy32.exe, Xcopy32.mod, Deltree.exe, Chkdsk.exe, Mode.com, Edit.exe, Edit.hlp, Diskcopy.com, Scandisk.exe, Label.exe, Help.hlp (DOS Help file, not available on all systems), Qbasic.exe, and another copy of Makeboot.bat itself.

Backupme.bat (DOWNLOAD. Tip- Hold SHIFT key down, and click link.)
A batch file to back up the contents of any folder to another folder. (Hidden and System files will not be backed up.)
   Backupme.bat can be a very quick and simple way to make a copy of files from a local drive to a file server drive; from a fileserver drive to a local drive; or between directories on a hard disk.
   To use the routine, simply call it with the names of the original and destination directories. The directory names should be contained in quotes. If the destination directory does not exist, it will be created. The below example will make a copy of the My Documents directory to a new directory called "My Documents BU" that is on the same "C:" drive.
backupme.bat "C:\My Documents", "C:\My Documents BU"
Backupme.bat is best run from a PIF (or DOS Shortcut file.) A sample PIF file is included, called: backupme.bat.PIF
   This PIF file is used as the example in the "Batch File Overview" section, above.
   The Cmd line field of this PIF is set to backup the C:\My Documents folder to a new folder called C:\My Documents BU. You can change these directories to whichever source and destination directory you may want. (If the destination directory does not exist, the routine will create it for you.)
   When you edit the PIF file, use the Cmd Line field. Add the names of the original (source) directory, a comma, and then destination backup directory. Enclose each directory name in quote marks. Add them after a space after the last entry in the Cmd Line field, such as:
C:\WINDOWS\COMMAND\BACKUPME.BAT "C:\My Documents", "C:\My Documents BU"

Setup_sp.bat (DOWNLOAD. Tip- Hold SHIFT key down, and click link.)
WINDOWS 98 ONLY
- Do not run this on a Windows 95, NT, or 2000 computer. You may have unexpected results. It was designed and tested for Windows 98 systems ONLY.
   Setup_sp.bat is a "setup" batch file. When run, it will install a number of other batch files and accessory items. It will copies files to the C:\Windows\Command directory, and will modify the Autoexec.bat file to run C:\Windows\Command\Start_sp.bat on startup.

Overview of Setup_sp.bat Actions

   The below explanations of each file may be somewhat confusing, so here is an overview: Setup_sp.bat will install these files, and modifies the computer's Autoexec.bat with AutoexecEdit.txt to run Start_sp.bat. Start_sp .bat will therefore run each time the computer is started. In turn, this program will itself run two files- Tempfix.bat, to empty the TEMP directory, and SPFixreg.reg, to force the Start Menu's Shut Down to default to Shut Down. (Tempfix.bat may cause problems with some installers, so read the notice below.)

Associated Files with Setup_sp.bat include:

Start_sp.txt, a text file with a copy of this text. This will be copied to C:\Windows\Command by Setup.sp.bat.

AutoexecEdit.txt, a text file that is used by Setup_sp.bat to modify the Autoexec.bat file. This text file is needed only once.

Start_sp.bat, a batch file that will run on startup, once the modifications in AutoexecEdit.txt are installed by Setup_sp.bat. This batch file will itself run two separate items. These are:

SPFixreg.reg will be run. This will reset the Start Menu's ShutDown option to be "Shut Down" instead of "Restart". SPFixreg.reg is a text file that is designed to be entered into the Registry of the Windows 98 system each time the computer starts up. SPFixreg.reg can be edited by any word processor. It contains instructions that force the Start Menu's "Shut Down" feature to default to "Shut Down", instead of the "previous setting" (such as Restart.) This resolves a very major annoyance with Windows 98 systems. NOTE: For server systems, SPFixreg.reg should be changed to make this menu item default to Restart, instead of Shut Down. Either edit the .reg file in two places to change "=dword:00000001" to "=dword:00000002", or rename the included file "C:\Windows\Command\SPFixregRESTART.reg" to SPFixreg.reg.

Tempfix.bat is a batch file that will empty the temp directory at C:\Windows\Temp as the computer starts up, as after a Restart or a Shut Down.
   Why do this? The C:\Windows\Temp directory is not normally emptied. The directory will, over time, fill up with "junk" and can slow performance of the machine. However, emptying the Temp directory on boot may confuse some installer programs. There is also a bypass option; see below.

NOTICE: Please Be Aware that software installers (Setup programs) may use the TEMP directory to hold software between restarts of the computer. Installing the Tempfix.bat startup routine will empty the TEMP folder after a restart. This can cause these installers to fail to run properly.
   
Using the Temp directory in this way is in violation of Microsoft's guidelines for writing installation programs. The only software that we have experienced this problem with, however, has been some older versions of Microsoft's own software...
Bypassing Tempfix.bat:
   Tempfix.bat can be BYPASSED for a single Restart by placing a file called "Tempkeep.txt" in the C:\Windows\Command directory. This file is just a "marker", and will be deleted (or renamed) when Tempfix.bat runs. There will be a file created by the batch file called "Tempclr.txt", which may also be renamed into "Tempkeep.txt".


 Desktop Systems
 

  
Contact us at:
info@softprose.com

Home | Services | Internet | Proposals | Books | Links | SoftProse | Email