Backing Up Configuration Files Why back up configuration files? Have you ever installed a program, found out you didn't like it and uninstalled it only to find that now something doesn't work properly or you are getting error messages? This can partly be avoided by keeping current backups of your configuration files, especially immediately before installing software. Should you decide that you want to remove the software, or perhaps roll back to previous software this will help in the event that changes to the registry or .ini files didn't get undone after removal of the software. Perhaps you had trouble installing some new hardware and after the aborted attempt Windows won't boot? Your dog ate your system.ini file? Whatever the reason, it sure would have been nice to have a backup. There are a few different ways of doing this. If you have Norton Utilities or a similar utility package you can make a rescue disk set. If you are running Windows 98, this problem almost takes care of itself with The Registry Checker utility that automatically makes a backup of the registry and system.ini and win.ini (more on this further down on the page). You can make a registry backup using Regedit and export the entire registry database to a .reg file (doesn't get the .ini files though), or you can simply copy the files to a directory and when problems arise, boot to Command Prompt and replace them. Before we get started, we need to make sure that you can see everything in Explorer windows. As an educated Windows user, there is no reason that you should let windows hide files and extensions from you. To get Windows Explorer to show all files and not hide file extensions, open Windows Explorer and click the View menu and choose: Options (Win95 without Internet Explorer 4 interface) or Folder Options (Win98 or Win95 with IE4 interface). Click the View tab and find the checkbox that shows all files. Also uncheck the box that "hides MSDOS file extensions". Now you'll be able to see hidden and system files and their file extensions. What Files Should I Backup? Typically, you should back up the system registry, the system.ini and win.ini files, perhaps your config.sys and autoexec.bat files (if present or important) and maybe MSDOS.sys (which in Win9x is a text based configuration file unlike previous versions of DOS). If you have more disk space than you know what to do with, you could also copy the entire Windows \System directory somewhere else in case you want to restore all the libraries. (this isn't really necessary, but would almost guarantee that you could recover from any software installation that went bad). Let's start with the system registry, it is a binary database of hardware and software settings contained in two files: System.dat and User.dat which are hidden and read only files. Make a folder on your hard drive and copy these files from the windows directory. Also copy win.ini and system.ini to this folder. If you are showing all files in windows explorer this is an easy task, you can just right click to copy and then right click on the destination folder and paste. It wouldn't hurt to copy Autoexec.bat, Config.sys and MSDOS.sys to this folder as well. Not very many programs would change your MSDOS.sys file, but maybe some "tweaking" utilities allow you to unknowingly make changes to this file, for example, to turn off the startup logo screen or some other feature of Windows. Does this all sound like a pain in the butt to do every time you want to install software or just make current backups of important configuration files? What's worse, when most of these files have attributes like hidden and read only, they have to be turned off before you can restore them using DOS. (You certainly cannot replace the registry while any Windows components are loaded). Create MSDOS Batch Files to Automate the Task I am going to show you how to make (provide for you) MSDOS batch files that will do this for you flawlessly and easily. All you'll have to do is double click the batch file from anywhere in Windows when you want to create or update your backups. Also, you'll make a restore batch file that you execute from the Command Prompt (only). A batch file is basically a text based file that contains DOS commands that are executed in sequence when you run the batch file. Batch files can be very powerful and can use simple programming commands as well. I recommend that you never run a batch file unless you view it and understand the commands that it is going to execute. While I would never do anything to harm you, some cretinous wretch could wipe you out with a single command in a batch file. For that reason I am going to go through the batch file with you step by step and explain the commands. If you are running Windows 98 and are not interested in the batch files, scroll down because I will also be providing information on how to effectively use the Windows 98 Registry Checker and the Scanreg utility to backup and restore configuration files. I will also provide information on how to use Regedit (Win95 and Win98) to make an additional registry backup. Backup Config Files - cfgbak.bat (Example) @echo This batch file must run from within Windows 95 or Windows 98 @echo off if EXIST c:\cfgbak\* goto next echo CREATING DIRECTORY C:\CFGBAK md c:\cfgbak goto next :next attrib -h -s %windir%\system.dat attrib -h -s %windir%\user.dat attrib -h -s c:\msdos.sys copy /B %windir%\system.dat c:\cfgbak /B /V /Y copy /B %windir%\user.dat c:\cfgbak /B /V /Y copy c:\msdos.sys c:\cfgbak /V /Y attrib +h %windir%\system.dat attrib +h %windir%\user.dat attrib +h +s c:\msdos.sys copy %windir%\system.ini c:\cfgbak /V /Y copy %windir%\win.ini c:\cfgbak /V /Y if EXIST c:\autoexec.bat copy c:\autoexec.bat c:\cfgbak /V /Y if EXIST c:\config.sys copy c:\config.sys c:\cfgbak /V /Y goto END :END The first line is telling you (will echo to your screen) that the batch file is to run from within Windows 9x and not from command prompt. The reason for this, is that I'm using the %windir% variable which if not used from within Windows, will return the root directory, which is not what we want and will result in file copy error messages. Not everyone's Windows directory is C:\Windows. The next line @echo off turns off the echo so the rest of the process won't make a mess of your DOS window. The @ tells it not to echo the echo command. Next, if the directory c:\cfgbak exists, the process will proceed to the commands defined under "next". If the directory doesn't exist, the "md" command that follows will create it. Next, we are removing the MSDOS file attributes necessary to copy the files. (you guessed it, the command is attrib) Next we are copying the two files that make up the system registry, and the file MSDOS.sys. Note the switches I am using with the copy command. The /B switch specifies that it is a binary file (by default, copy treats files as ascii). This switch is not really necessary under normal circumstances, but since these are very important files I want to take extra precautions to ensure that the files are written and verified correctly. Using the /B switch ensures that the entire file is copied, regardless of any file markers within. The /V switch verifies the source and destination files to ensure that they are identical (eg. not corrupted). The /Y switch suppresses prompting when files are overwritten. This is necessary because the batch file is to be used not only to create the backups but to update them on a regular basis. Next, we reset the MSDOS attributes that we changed. This is important so that the files are protected. Win.ini and System.ini do not have attributes that need to be removed and they are ascii text based files so we simply copy them. Autoexec.bat and Config.sys may not be present on your system, as if all your hardware is plug and play and you do not run DOS programs or load any real mode drivers they are not needed. If they exist, however, they will be copied. Note that if they are blank (0 byte) files, they will not be copied and you will see a "(0) files copied" line in the output of the batch file. This is nothing to worry about. You can either copy the text from the textbox to notepad and save it as cfgbak.bat (or any other name with the extension.bat), or you can download the zip file. Note that I left the batch file to restore the backups as a text file. (restcfg.txt) You will have to rename it so it has the extension .bat and/or edit it. (I did this just as a precaution, so someone doesn't immediately run it by double clicking) Download cfgbak.zip (cfgbak.bat and restcfg.txt) at http://www.PCNineOneOne.com/dloads/cfgbak.zip How to Use this Batch File Simply copy it to any folder in Windows or put it on your Desktop. Double click it at any time to create or update your backups. If you want to add more files to be backed up, or you want to change the location of the backup destination, I think I have provided you enough information so you can edit it yourself. Once again, feel free to Email me. Be careful with the placement of command line switches. Restore Config Files - restcfg.bat Note that this batch file MUST run from Command Prompt Only. That is, press F8 before windows starts to boot and choose Command Prompt Only from the boot menu. Also very important, if your windows directory is anything other than C:\Windows you MUST edit this file accordingly. Change the destination of each command that copies a file to the windows directory. Be careful not to affect the position of command line switches. I cannot use a variable to represent the Windows directory in this case. If you accidentally double click this file from within Windows I have given you the opportunity to abort. Press ctrl+c (press and hold the ctrl key while pressing the letter c) If you followed my explanation of cfgbak.bat then you should understand the commands in this batch file. @echo This batch file must run from COMMAND PROMPT ONLY @echo It will replace your registry & configuration files from backup @echo Press any key to continue or ctrl+c to terminate process @pause > null @echo off attrib -r -h -s c:\windows\system.dat attrib -r -h -s c:\windows\user.dat attrib -r -h -s c:\msdos.sys copy /b c:\cfgbak\system.dat c:\windows /b /v /y copy /b c:\cfgbak\user.dat c:\windows /b /v /y copy c:\cfgbak\msdos.sys c:\ /v /y attrib +r +h c:\windows\system.dat attrib +r +h c:\windows\user.dat attrib +r +h +s c:\msdos.sys copy c:\cfgbak\system.ini c:\windows /v /y copy c:\cfgbak\system.ini c:\windows /v /y if EXIST c:\cfgbak\autoexec.bat copy c:\cfgbak\autoexec.bat c:\ /v /y if EXIST c:\cfgbak\config.sys copy c:\cfgbak\config.sys c:\ /v /y goto END :END How to Use this Batch File This batch file should be copied to the root directory of drive C: so that you can simply type "restcfg" from the C:\> prompt. It MUST be executed from Command Prompt Only because the registry cannot be overwritten from within Windows. Either copy the text from the textbox to notepad and save it as restcfg.bat in the root directory (edit it first if necessary), or download the zip file. If you download the zip file, you will have to rename restcfg.txt to restcfg.bat after editing. Warning! Make sure that your backups are current. If you restore an old backup it could be fatal if you've made major changes to the operating system or hardware since the backups were created. For example, if you've installed Internet Explorer 5 and restore your registry from a backup predating that, expect that your computer won't boot properly. An example of correct usage would be to make current backups immediately before installing new software, then if it doesn't go as planned UNINSTALL the software and if your system isn't right you can restore the configuration files. Download cfgbak.zip (cfgbak.bat and restcfg.txt) at http://www.PCNineOneOne.com/dloads/cfgbak.zip If you are running Windows 98 The batch files I made will work equally as well as in Windows 95, however there is a much easier and automated method provided with Windows 98. Once a day (when your computer boots) by default, a backup of the two registry files as well as system.ini and win.ini is created in cabinet files (compressed archives) in the hidden directory \windows\sysbckup. By default, 5 backups are kept. If you want to have a look, make sure Windows Explorer is set to show all files and extensions and go to that directory and look for files named "rb00x.cab" where the x is a number. The ScanregW (Win32 version) runs at startup and checks the registry for corruption, compacts it when it detects wasted space, and makes these backups once a day. If at any time you want to make a current backup, simply go to start/run and type "scanregw" and hit enter. Click "Yes" to answer the question "Your registry has already been backed up today, would you like to back it up again?" Use Scanreg to Restore the Registry and .ini Files There is a real mode command line utility called scanreg.exe that is used from the Command Prompt Only boot option that can be used to "fix" or "restore" a damaged registry (as well as make a backup if desired). To see the available switches, type SCANREG /? To attempt to repair a damaged registry, type SCANREG /FIX To restore a damaged registry and ini files (that is, replace them from the backup) Type the following command. This will allow you to choose the backup you want to restore from. SCANREG /RESTORE Here is an undocumented switch for scanreg that forces it to compact the registry by eliminating wasted space: SCANREG /OPT Change Default Behavior of Scanreg You can make Scanreg include additional files in the backups, or change the location of the backup cab files, or make it keep more than five backups by editing the Scanreg.ini file in the Windows directory. Open it with notepad and you will see lines commented out with semi-colons that explain how to make these changes. Email Me for specific questions you may have. Additionally - Use Regedit to back up Registry The registry editor, Regedit.exe, also provides a method for backing up and fixing or restoring the registry. Easiest way to open Regedit in the Windows directory is to go to start/run and type regedit and hit enter. In regedit, go to the Registry menu (where "File" normally is) and choose "Export Registry File". Make sure that the bullet "All" is checked under "Export Range". Save the .reg file (eg. RegBak.reg) in the root of drive C: for easy access. There are two ways that you can use this backup. At any time in Windows you can double click the .reg file to "merge" it with your registry. This may correct a problem, however it cannot remove keys, only add keys or change values of existing keys. If your registry backup is not current it could also cause problems, or perhaps add erroneous keys if you've since uninstalled software. To use this backup to restore a corrupt registry, boot to Command Prompt Only and type the following command. REGEDIT /C REGBAK.REG The /C switch tells it to completely rebuild the registry from the text based .reg file. This is also used to compact the registry. (eliminate wasted space) http://www.PCNineOneOne.com