A Bunch of Handy Batch Files


Menu
Backup/Rescuue "One-Minute Life Saver"
Backup/Rescue SOS.bat
How to print a directory listing from Explorer Window
Copy the contents of the Favorites folder to a File
A Text File of All The Files and Your Windows 95/98 CD
Exit Windows 98 Automatically Using a Batch File
More Coming.

Here's a "One-Minute Life Saver" .bat for backing up important system files.
First, create a destination folder (such as D:\VAULT) in which to save your backups. It's better-although not essential-to create the folder on a drive other than your boot drive, if possible. Next, create a text file called LIFESAVE.BAT and place it in your root directory. Edit the file and copy the following lines into it, where D:\VAULT is the name of the destination folder you created:

copy C:\AUTOEXEC.BAT D:\VAULT
copy C:\AUTOEXEC.DOS D:\VAULT
copy C:\CONFIG.SYS D:\VAULT
copy C:\CONFIG.DOS D:\VAULT
copy C:\WINDOWS\CONTROL.INI D:\VAULT
copy C:\WINDOWS\SYSTEM.INI D:\VAULT
copy C:\WINDOWS\WIN.INI D:\VAULT
attrib -r -h -s C:\MSDOS.SYS
attrib -r -h -s C:\WINDOWS\USER.DAT
attrib -r -h -s C:\WINDOWS\SYSTEM.DAT
copy C:\MSDOS.SYS D:\VAULT
copy C:\WINDOWS\SYSTEM.DAT D:\VAULT
copy C:\WINDOWS\USER.DAT D:\VAULT
attrib +r +h +s C:\MSDOS.SYS
attrib +r +h +s C:\WINDOWS\USER.DAT
attrib +r +h +s C:\WINDOWS\SYSTEM.DAT

Now you can back up the files by double-clicking on LIFESAVE.BAT.

You can automate the above tip by auto-running the batch file whenever you launch Windows. First, open your C:\WINDOWS\START MENU\PROGRAMS\STARTUP folder. Right-click on the background and select New/Shortcut. Enter C:\LIFESAVE.BAT in the Command Line field. Give the new shortcut a name, such as "One-Minute Life Saver." Finally, right-click on the shortcut, choose Properties and then the Program tab. At the bottom of that tab, check the Close On Exit box. Now each time you start your machine, the One-Minute Life Saver will run automatically in a DOS window and then close automatically.

Personally, I wouldn't run it on Startup. Also you can change the names and locations of the files to your liking.

To restore here's the "Restore.bat"

copy D:\VAULT\AUTOEXEC.BAT C:
copy D:\VAULT\AUTOEXEC.DOS C:
copy D:\VAULT\CONFIG.SYS C:
copy D:\VAULT\CONFIG.DOS C:
copy D:\VAULT\CONTROL.INI C:\WINDOWS
copy D:\VAULT\SYSTEM.INI C:\WINDOWS
copy D:\VAULT\WIN.INI C:\WINDOWS
attrib -r -h -s C:\MSDOS.SYS
attrib -r -h -s C:\WINDOWS\USER.DAT
attrib -r -h -s C:\WINDOWS\SYSTEM.DAT
copy D:\VAULT\MSDOS.SYS C:
copy D:\VAULT\SYSTEM.DAT C:\WINDOWS
copy D:\VAULT\USER.DAT C:\WINDOWS
attrib +r +h +s C:\MSDOS.SYS
attrib +r +h +s C:\WINDOWS\USER.DAT
attrib +r +h +s C:\WINDOWS\SYSTEM.DAT



Backup/Rescue SOS.bat

If you find you have messed up and know a Registry Save would have been in order but you forgot; then SOS.bat is for you. Your user.da0 and system.da0 are images of the last boot. So, below is how to bring that "Last Good Image" back to life.
I have all my .bat files in a directory called C:\Batch, and have C:\Batch in my path statement in the "autoexec.bat".

@ECHO OFF
cd c:\windows
attrib -h -r -s system.dat
attrib -h -r -s system.da0
attrib -h -r -s user.dat
attrib -h -r -s user.da0
copy system.dat system.bak
copy user.dat user.bak
copy system.da0 system.dat
copy user.da0 user.dat



How to print a directory listing from Explorer Window

This tweak lets you right-click on any folder icon and tell Windows to print a list of all the files and subfolders it contains.
1. Make a .bat file like so:

dir/s/oe %1 /o:gn > "%temp%\Dir Listing"
cd\
if not exist dirlist\NUL md dirlist
if exist c:\dirlist\Dirlist.txt  goto Two
move "%temp%\Dir Listing" c:\dirlist\Dirlist.txt
goto End
:Two
move "%temp%\Dir Listing" c:\dirlist\Dirlist2.txt
:End
cd dirlist
call nextfile Dirlist txt
cd\
c:\dirlist\%Highest%

This batch file will let you run before and installation creating "Dirlist.txt".
Then, again after an installation creating "Dirlist2.txt".
Then use a good file compare utility like I use, ExamDiff Pro. You can get the freeware version or the Pro version at
http://www.nisnevich.com/

2. Open Windows Explorer, choose View, Options (or Folder Options), and click on the File Types tab. Select File Folder, then click on Edit and New. Fill in the New Action dialog box (put in any name you want, example "Print Directory Listing" and it will appear on right click) and save your changes.

3. Right-click on any folder icon and choose Print Directory Listing to send a detailed directory list to the newly created Dirlist directory/folder.

NOTE:
You can modify this .bat file to you liking, for instance:
The very first Dir command can be just [dir]
The /s shows you the sub-directories
The /oe tells it to arrange the files in acceding order by the extensions.

This is a great for before and after installation comparison.
Thank You Scott Pearce for re-writting this file for me.
You can download it Here

See Keep Your System Clean

See how to print to file!



Copy the contents of the Favorites folder to a File

When a file is too large for Notepad, you get a message telling you that the Favorites folder is too large to open in Notepad and asking if you would like to open it in Wordpad. When you answer Yes to this question, you'll get an error message and the batch file will fail.

To generate the batch file, run Notepad and type in the following:

dir "c:\windows\favorites" /s /b /l > c:\tmp.wri
write c:\tmp.wri /p
del c:\tmp.wri

Now, choose File, Save As and name the file PrintFav.bat. Save the file in a folder of your choice.
This may be a good idea anyway, since most people probably have numerous listings in the Favorites folder.

If you'd like to save the file, you can delete the batch file line

del c:\tmp.wri

This deletes the file when you finish printing it. Since we changed the file's extension to .wri, you can double-click the file to open it in Wordpad.



A Text File of All The Files and Your Windows 95/98 CD

This comes in really handy when you get an error message pointing to a file and you need to know if that file comes from your system CD or a third party file.

For Windows 98
@C:
@CD\
@MD \EXTRACT
@FOR %%x IN (H:\WIN98\*.CAB) DO EXTRACT /D %%x >> C:\EXTRACT\LISTCAB.TXT
@EDIT C:\EXTRACT\LISTCAB.TXT

As you can see "H:\WIN98\*.CAB" would be the drive letter for you CD-ROM, you may have to adjust that.
For Windows 95, the .bat file is the same except for "H:\WIN98\*.CAB" you change that to "H:\WIN95\*.CAB".

Try it, you'll like it.



Exit Windows 98 Automatically Using a Batch File

These are commands or batch files commands that you can use to create a batch file that automatically restarts Windows 98.
They can come in handy when troubleshooting Shutdown Problems.

You can use either of the following commands in a batch file to restart Windows 98 automatically:

runonce.exe -q

rundll32.exe shell32.dll,SHExitWindowsEx n

where n is one, or a combination of, the following numbers:

0 - LOGOFF

1 - SHUTDOWN

2 - REBOOT

4 - FORCE

8 - POWEROFF

The above options can be combined into one value to achieve different results. For example, to restart Windows forcefully, without querying any running programs, use the following command line:

rundll32.exe shell32.dll,SHExitWindowsEx 6

NOTE: Using the FORCE option can cause programs to lose data.

Below is an explanation of each available option used with the above command line:

LOGOFF - Shuts down all running processes, then logs the user off.

POWEROFF - Shuts down the system and turns off the power. The system must support the power-off feature.

REBOOT - Shuts down the system and then restarts the system.

SHUTDOWN - Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.

FORCE - Forces processes to terminate. When this flag is set, Windows does not query running applications to inform them that Windows is shutting down. This can cause the applications to lose data, therefore, you should only use this flag in an emergency.

The "rundll32.exe shell32.dll,SHExitWindowsEx (n)" command mentioned above can be called from the RunOnce registry key.

The runonce.exe -q command mentioned above restarts the computer after a 15 second delay. There are no other options when using this command line, and it cannot be called from the RunOnce registry key.

See RunOnce Registry Key Definition:

There are seven Run keys in the registry that cause programs to be run automatically:

1. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

2. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

3. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce

4. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

5. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ RunServices

6. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ RunServicesOnce

7. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ RunOnce\Setup
 

Keys 1-4 are run each time a new user logs in.

Keys 5-6 are run in the background when the logon dialog box first appears, or at this stage of the boot process if there is no logon. These keys are for background services such as remote registry service and are run only once per boot.

Key 7 is run as part of Setup's first-boot activities, or after you use the Add/Remove Programs Wizard.

Under each of these keys is a series of values. The values are used to allow multiple sub-entries to exist without overwriting one another.

The data value for a value is a command line. By default, Run keys are ignored in Safe mode. For keys 3-4, the command line can be prefixed with an exclamation point to defer deletion of the value until after the command has been completed.

For keys 3, 4, and 6, the value is deleted before the command line is run unless overridden as noted above. As a result, if a RunOnce operation fails to run properly, the component that failed will not be asked to run again the next time you start the computer.

Key 7 is used only by Setup. This key displays the progress dialog box as the keys are run one at a time. For key 7, the name of the value is the name that is displayed in the dialog box.


  • Back To The Top    • Back To Home