Compacting the Windows9x Registry
Patrick Wullaert
<Home>
What is the Registry ?
If you're asking that question, you shouldn't really be tampering with what is the heart of your operating system. This guide is only intended for people who have at least some basic knowledge about the Registry. However, if you feel confident by all means read on and give it a try!
(Please note that these instructions are only valid for a single user system, not for one with multiple profiles!)
Why Compact ?
You may - or may not - have noticed that the Windows Registry files, the hidden files system.dat and user.dat in the Windows\System directory, keep growing in size. Even if you uninstall all your applications, the size of these files will not decrease. That's because information in the Registry is not deleted but overwritten with what is basically garbage.
Because the Registry is loaded upon starting Windows, the bigger it is, the longer it will take to boot your system.
Furthermore a place where garbage accumulates is not a clean place. The same goes for the Registry. After a while a big, untidy Registry may start causing little annoyances or unexpected errors.
For both these reasons it's advisable to regularly clean and compact the most vital of system files - especially if you (un)install a lot of software.
So how is it done ?
Don't let the length of this guide impress the hell out of you; it contains a lot of 'ifs'. It's fairly easy, though you should follow the instructions carefully. It's certainly not a 'success guaranteed' procedure. Several things can go wrong. Therefore it's essential to make a backup of your system files before proceeding any further. If at any given point something goes wrong, you will then be able to restore your system quickly to the state it was before the changes. Now for the cleansing procedure (read it from top to bottom and don't skip any steps !) :
Step 1 : Check if you have the correct Regedit.exe file
Go to Windows Explorer and in the left pane highlight the Windows directory by left-clicking on it.
Ask for an alphabetical listing in the right pane and browse down to Regedit.exe.
Right-click on the name and choose Properties.
Click on the Version tab. The version number should be 4.00.1111 or later. If it's an earlier version, you should download the patched Regedit from http://www.users.dircon.co.uk/~flibble/regsmall.html.
Rename the original file as 'Regedit.old' before moving the newly-downloaded Regedit.exe into your Windows folder.
The Registry Editor of older Windows95 systems, dating from before OSR2, contains a bug because of which it has a problem with large Registries.
Step 2: Back up your present system files
I encourage you to use the excellent WinRescue9x by Ray Geide. It's the safest and most efficient way of backing up your system files.
Assuming you don't have it, reboot your computer, press F8 on seeing 'Starting Windows' and choose 'Command Prompt Only' from the boot menu (usually #6). This will boot you into Real DOS Mode, halting the boot process before Windows itself loads. You will see 'C:\>' with the cursor flashing. This is the Dos Prompt, or Command Prompt (it is prompting you to type in a command). Enter the
following commands, by typing them exactly as given, then pressing the Enter key:
[ If you're not automatically in the Windows directory, go there first by typing CD \windows ]
attrib -r -a -s -h system.dat
attrib -r -a -s -h user.dat
copy system.dat system.dax
copy user.dat user.dax
Step 3: Clean out the Registry using EasyCleaner and RegClean
This step is optional, and you may skip it if you wish. Still, I recommend that you give it at least a try.
Type win to start Windows and run EasyCleaner, a small, free program that you can download from http://www.majorgeeks.com/download414.html. Select 'Clean Registry' (as you'll see it can do quite a bit more than just Registry cleaning but in this guide we will stick to that aspect of the utility), then click on the 'Search' button at the top of the newly opened screen. Just let the program run the search, next 'Select All' (or take your own pick if you're more experienced), then 'Delete' and finally confirm the deletion.
EasyCleaner removes quite a few unnecessary entries (like MRUs - Most Recently Used lists in programs) but is what I call a low impact Registry cleaning tool. It doesn't touch delicate keys at all, making it very safe to use (I've never had any problems with it). If you have any doubts, you may always decide not to use it.
Next, if you don't have it already, download Microsoft's RegClean4.1a from here (difficult to find at Microsoft's own site!). This free utility tracks down and removes certain types of OLE errors which may be present in the Registry.
You just install the program in a directory of your choice - I prefer the root C:\ - and run it. It starts scanning your system right away.
When it's finished it'll pop up two buttons: 'Fix Errors' and 'Exit'. If the 'Fix Errors' button is ghosted (not active) after the scan, just Exit RegClean - it didn't find anything to remove - and continue with Step 4.
If it has found any errors, obviously you choose to Fix them or you wouldn't have run the program. The relevant keys are then removed, so your Registry will again be a bit smaller after compacting.
When it removes something, RegClean automatically creates a ' .reg' file containing the deleted keys in the same directory you installed it. Don't delete this file until you've verified your system still works as it should - in fact, keep the file until next time you compact.
You can have a look at exactly what was removed by running NotePad and opening the ' .reg' file created by RegClean. Don't try double-clicking the file from within Explorer to get to its contents ! That will only merge the removed key(s) back into your Registry again. You may, however, right-click on it and choose 'Edit'. As with Registry itself, unless you understand exactly what each key does, just stick to looking for the present.
At this point restart Windows and check if everything behaves all right, especially if you know that keys relating to still existing applications have been removed (e.g. Netscape, MicroSoft Internet Explorer and GetRight settings are notorious for disappearing !). If you notice anything irregular which can be attributed to the removal of certain keys by RegClean, start up Windows Explorer, go to the RegClean directory and double-click on the ' .reg' file it created - the deleted entries will automatically be added to the Registry again. If you're really experienced at this you can edit the ' .reg' file to have only the keys you want added back. (Some programs' keys can be restored simply by re-installing the application, but this is a matter of trial and error).
Reboot your computer into Real DOS mode ('Command Prompt Only' from the boot menu - usually #6). This will boot you into Real DOS Mode, halting the boot process before Windows itself loads. You will see 'C:\>' with the cursor flashing. This is the Dos Prompt, or Command Prompt (it is prompting you to type in a command).
Step 4 : Export the Registry
At the prompt enter the following commands :
[ If you're not automatically in the Windows directory, go there first by typing CD \windows ]
regedit /e compact.reg
This should export your Registry to a file called compact.reg in the Windows directory, which is basically a text file. This will take some time without any visual representation so don't panic.
If you don't receive an error just continue with step 5.
If you get an error message - usually "Error accessing the registry: The file may not be complete" - during this step, then : 1) don't worry about your system function - nothing in this step affects it, but 2) don't proceed any further as you're bound to run into massive problems ! Instead start Windows again by typing win.
Run the Registry Editor from within Windows : click the Start button, select Run, type 'regedit' and press Enter.
Highlight 'My Computer' (this is usually done by default) and then select 'Export Registry File' from the Registry menu. Choose 'Windows' as the saving directory, and enter 'compact' as the filename (the .reg extension will be added automatically).
Secondly, highlight HKEY_LOCAL_MACHINE (left-click on it). Again choose 'Export Registry File' from the menu and save the export file in the Windows folder as 'HKLM'.
Thirdly, do the same with the HKEY_USERS key and save it as 'HKU'.
Close the Registry editor and boot to Real DOS mode as per above (if necessary go to the Windows dir by typing CD \windows).
Step 5 : Rebuild the Registry
Rebuild the Registry using the compact.reg file by entering :
regedit /c compact.reg
This step may take a long while; there have been reports mentioning several hours. There will be an indicator showing a percentage of how much is done. Don't worry if this counter seems to hang at a certain percentage. This is normal behaviour. Do not disturb the operation !
Step 6 : Check your system function
This is a very important step, obviously.
Try to restart Windows by typing win. It's a good sign if it boots all right and you see your trusty desktop (in the right resolution and with the right colour depth) and hear the familiar startup .wav file playing (if you have it enabled).
Check if all programs which usually load during booting (for instance the Office task bar, anti-virus software, Dunce, the resource monitor, etc.) have indeed all loaded now.
Check whether the list of installed software still exists. Go to Settings \ Control Panel \ Software and see if the list looks complete.
If all looks well, continue with step 7. If not...
Troubleshooting Guide
Go to Real DOS mode and decide which of the following describes your situation :
- You previously received an error whilst executing 'regedit /e' :
Create a new Registry from just HKEY_LOCAL_MACHINE by entering the following command :
[ If you're not automatically in the Windows directory, go there first by typing CD \windows ]
regedit /c HKLM.reg
- If you receive an error during this process, there's a serious problem in the HKEY_LOCAL_MACHINE key of your Registry. A Windows 9x reinstallation may be in order, or you could go through the tedious task of trying to track down and remove the error manually, using the HKLM.reg file and a text editor. If you decide to reinstall, check the Re-installing Windows 9x article.
For the moment, restore the previously saved Registry files :
attrib -r -a -s -h system.dat
attrib -r -a -s -h user.dat
copy system.dax system.dat
copy user.dax user.dat
- If you didn't get any errors, import the HKEY_USERS key into the newly constructed Registry by typing :
regedit HKU.reg
[ Note there aren't any switches specified ! ]
- If you receive an error during this last process, there's a serious problem in the HKEY_USERS key of your Registry. A Windows 9x reinstallation may be in order, or you could go through the tedious task of trying to track down and remove the error manually, using the HKU.reg file and a text editor. If you decide to reinstall, check Re-installing Windows 9x.
For the moment, restore the previously saved Registry files as described above.
- If you didn't get any errors, recheck your system function as described in this step (step 6). If it works you should be home-and-dry and can continue with step 7. If it still doesn't work, restore to your previously saved Registry files, as above, and consider a reinstallation using the Re-installing Windows 9x guide.
- You didn't receive any errors before :
Then start Windows again by typing win.
Run the Registry Editor from within Windows : click the Start button, select Run, type 'regedit' and press Enter.
Highlight 'My Computer' (this is usually done by default) and then select 'Export Registry File' from the Registry menu. Choose 'Windows' as the saving directory, and enter 'compact' as the filename (the .reg extension will be added automatically).
Secondly, highlight HKEY_LOCAL_MACHINE (left-click on it). Again choose 'Export Registry File' from the menu and save the export file in the Windows folder as 'HKLM'.
Thirdly, do the same with the HKEY_USERS key and save it as 'HKU'.
Close the Registry editor, boot to Real DOS mode and continue with step 5. If you did exactly that before and ended up here again, restore to your previously saved Registry files as per above description and consider a reinstallation as per Re-installing Windows 9x.
Step 7 : Run FixReg
If you're running Windows 98 or better, you can safely skip this section and continue with Step 8.
Windows 95's RegEdit, however, cannot in itself correctly import exported keys containing strings containing <CR> (Cursor Return) and/or <LF> (LineFeed) characters. They will just drop out. The program FixReg (which you can get from here) addresses this problem by scanning a file exported by regedit /e for these <CR> and <LF> chars and then lets the user decide whether or not to enter them into the newly created Registry.
You may wonder why we run FixReg after we've already created a new Registry. Surely if some characters have dropped out they won't be present in the new Registry anymore, right ? Right ! But first you must understand keys only get left out during the regedit /c process not during /e. Therefore, the file compact.reg will still hold the keys containing <CR> and <LF> which eventually get omitted from the newly created Registry. FixReg tracks down these keys in compact.reg and checks if they were left out of the new Registry. If so it re-enters them.
Run FixReg from within Windows. Select 'Open' from the File menu and point the program to the Windows\compact.reg file.
FixReg will start scanning immediately after that and will report problematic keys. You needn't do anything but press the Return key. The default action assigned to the Return key will always be the right action, so don't worry.
When the program finishes, all <CR> and <LF> characters will have been correctly entered in the new Registry.
Close FixReg.
Step 8 : Perform a final check
Reboot Windows yet another time. I know it's a drag but it's essential. If you don't do a thorough system check after compacting, some serious - even fatal - errors may go unnoticed until it's too late. Do not install or remove any soft- or hardware or make any drastic changes to your system's settings just yet !
Run as many applications as possible - complicated apps which rely upon a lot of Registry settings and DLLs are ideal.
Connect to the Internet and check out the different services : Web, FTP, IRC, ICQ, e-mail, Newsgroups ...
It's very likely everything will be fine and if indeed so continue with step 9.
If you do encounter problems, try to evaluate how severe they are. If only one or two of your applications have lost their settings but otherwise everything's fine, just re-enter those settings; a tiny, however irritating, problem like this doesn't warrant other actions.
If some application refuses to run, perhaps it's easier and faster to just re-install it ?
You have to consider seriously whether re-entering settings or re-installing applications doesn't outweigh : a) going back to a bloated Registry by restoring to your previously saved Registry files, or b) re-installing Windows !
Step 9 : Finalising the compacting process
If you reached this step, you'll have a smaller Registry (check the new size of the system.dat and user.dat files) and a smoother and faster running system (although on fast machines that may often not be readily noticeable).
The only thing left to do, is to delete the temporary files you created in the Windows directory - they take up a fair amount of disk space : system.dax, user.dax, compact.reg and eventually hklm.reg and hku.reg. You may wish to postpone this deletion until you're absolutely sure everything's in order, or just until the next time you compact.
Congratulate yourself on a job well done !
<Home>
| Acknowledgements |
A lot of the instructions on this Web page are based upon the invaluable comments and tips by Roy Lehrer, author of the reference SmallReg and Ray Geide, author of the absolutely best Registry backup program WinRescue9x.
Thanks also to Bob Downing, George Snell and Steve Walker who inspired me to write this guide and without whose tweaks and moral support I probably wouldn't have finished it. |
| Contact me |
If you're experiencing problems related to this topic but not mentioned in this guide,
or if you detect inaccuracies,
please drop me a line.
I will, however, accept no responsibility for any loss, damage or injury which may result from following any suggestions or procedures. Nor can I guarantee or accept responsibility for the fitness or operation of any recommended software !
|