d:
cd \win95
attrib -s -r -h system.dat
attrib -s -r -h user.dat
copy system.dat c:\savereg
copy user.dat c:\savereg
attrib +s +r +h system.dat
attrib +s +r +h user.dat
c:
cd \savereg
copy c:\autoexec.bat *.dat
copy c:\config.sys *.dat
dir
To see how it works, let us consider a few commands at a time.
d:
cd \win95
The above two commands select the drive and directory containing Windows 95. They may be different on your computer. Your Win95 may be on drive C instead of drive D, if so change the first command. And it may be installed in a directory called "windows" instead of "win95", in which case change the second command.
attrib -s -r -h system.dat
attrib -s -r -h user.dat
These two commands remove the system, read-only, and hidden attributes of two files, system.dat and user.dat; these two files constitute the "registry". Once these attributes have been removed, the files can be copied.
copy system.dat c:\savereg
copy user.dat c:\savereg
These two commands copy the system.dat and user.dat to a special directory I had already created on drive C, i.e. "c:\savereg".
attrib +s +r +h system.dat
attrib +s +r +h user.dat
Once the registry files have been copied, these two commands restore the system, read-only, and hidden attributes to the two registry files.
c:
cd \savereg
The registry itself is now backed up, but before the bat file ends I want to preseve a copy of config.sys and autoexec.bat. The above two commands change to the drive and directory where I copied the two registry files.
copy c:\autoexec.bat *.dat
This copies the autoexec.bat file from the root directory, but instead of it being called autoexec.bat, in the savereg directory the file will be called autoexec.dat.
copy c:\config.sys *.dat
This copies the config.sys file from the root directory, but instead of it being called config.sys, in the savereg directory the file will be called config.dat.
dir
This command does a directory list of all files in the savereg directory. Notice that there are now four files with the extention dat. I then notice the largest numeric extention of other files, add one to it, and do a rename to rename all four "dat" files to that number. For example, assuming the largest number is 6, I would manually execute the command "ren *.dat *.7".
Here is the GETREG.BAT file that I use on the old luggable to restore a particular set of registry files:
if %1x == x goto :error
d:
cd \win95
attrib -s -r -h system.dat
attrib -s -r -h user.dat
copy c:\savereg\system.%1 *.dat
copy c:\savereg\user.%1 *.dat
attrib +s +r +h system.dat
attrib +s +r +h user.dat
goto :end
:error
echo Need to know which one
dir system
:end
To understand this BAT file, let us again look at it one or two lines at a time.
if %1x == x goto :error
When one invokes GETREG one needs to indicate which set of files (set 6, set 7, set 8, etc.) are to be restored. One restores set 6, for example with the command "GETREG 6". This parameter is seen by the BAT file as "%1" (the 1st parameter to the BAT file). If the first paramater followed by the character "x" is the same as the character "x", then the first parameter must be NULL (i.e. it must have been left out), and therefore the BAT file will transfer control to the line ":error". If this transfer does not take place, and if the following instructions are executed, then "%1" is presumed to represent the set to be restored.
d:
cd \win95
These two commands switch to the Drive and Directory where Windows 95 is installed on the luggable. You would need to change these to the drive and directory it is installed on your computer.
attrib -s -r -h system.dat
attrib -s -r -h user.dat
These two commands remove the system, read-only, and hidden attributes on the current registry, so that they can be overwritten by the following two commands
copy c:\savereg\system.%1 *.dat
copy c:\savereg\user.%1 *.dat
These two commands take the specific set of system and user files in the C:\savereg directory that correspond to "%1" and copy them to the current drive and directory (where Windows 95 is), and they restore the "dat" extention to the files.
attrib +s +r +h system.dat
attrib +s +r +h user.dat
Now that the restored registry files are in-place, these two commands restore their system, read-only, and hidden attributes so that they will be protected from accidental modification.
goto :end
The batch file has now accomplished its objective, so this command transfers control around the ":error" code and takes it to the end of the file. Notice I did not restore the autoexec.bat and config.sys files. Currently I have not seen a need to do that, but if I did, the SAVEREG file did capture the files that were active at the time those registry files were backed up, and I could restore them if I wished. I could also add commands to SAVEREG to backup other files like WIN.INI or SYSTEM.INI or MSDOS.SYS if I felt the need, and if I did that, I might elect to have restored them as well before transferring control to ":end".
:error
echo Need to know which one
dir system
These instructions get control only if the first statement in the BAT file found that the first parameter had been eliminated, in which case it would echo the statement "Need to know which one" reminding the user to indicate the particular set of registry files to be restored, and then it would do a directory list of all of the "system" files, so that he would see by the extensions, which backup sets were available to be restored.
:end
This command ends the BAT file. If ":error" got control it would be encountered after the directory list had been done. If the BAT file did restore a set of registry files, the "goto :end" would have transferred control to the ":end" command.
Some may say all of this is nice for Windows 95 users, but I still use Windows 3.1. What should I do? That is a reasonable question. Here is a copy of the PRESERVE.BAT file that I use in my Windows 3.1 system. Note that this set of files uses a directory I created on my C: drive called "autoconf", because it contains backup sets of autoexec.bat and config.sys files, among others.
if %1x == x goto :noparm
pkzip c:\autoconf\%1.zip c:\autoexec.bat c:\config.sys e:\windows\*.ini e:\windows\*.grp
goto :end
:noparm
pkzip c:\autoconf\initial.zip c:\autoexec.bat c:\config.sys e:\windows\*.ini e:\windows\*.grp
:end
if %1x == x goto :noparm
As in GETREG above, this BAT file checks to see if a file name (up to eight characters) was provided when PRESERVE was executed, such as "preserve office" which I might use right after installing the Microsoft Office files, and if I did, it would create a backup set in a file called office.zip. If I left off the paramater, I would not abort, but would rather just update the files in "initial.zip".
pkzip c:\autoconf\%1.zip c:\autoexec.bat c:\config.sys e:\windows\*.ini e:\windows\*.grp
This command uses PKZIP to create a ZIP file with a particular file name in the c:\autoconf directory. This file will contain a copy of the current autoexec.bat file, the current config.sys file, all of the ini files in e:\windows (which is where I have windows 3.1 installed), plus all of the "grp" files (which contain the icons for each program in each program group).
goto :end
Once the zip file has been created this file is finished, so it transfers control to the end of the BAT file.
:noparm
pkzip c:\autoconf\initial.zip c:\autoexec.bat c:\config.sys e:\windows\*.ini e:\windows\*.grp
If no parameter was specified in the PRESERVE command, this code would get control, and PKZIP would be used to update the autoexec.bat, config.sys, and all ini and grp files in initial.zip, replacing files if they were already there, and adding them if they were not already there.
:end
The ":end" file represents the end of the bat file, to which the "goto :end" command can transfer control.
For more information on the Tulsa Computer Society click here