On CBSSports.com: Mike Tyson's daughter dies in accident

Learn to rebuild the Windows registry from DOS

Tags: John Kowaleski A+

  • Save
  • Print
  • Recommend
  • 6

Takeaway: A corrupt Windows registry can be a nightmare. Your PC won't boot, so it looks like you'll have to reinstall Windows. Before you do that, here's a way to rebuild the registry through DOS that could save you some time and effort.


It's amazing how many Windows problems are caused by a faulty registry, from Windows protection errors on startup to Windows hanging on shutdown. Severe problems resulting from severe registry damage may require a fresh install of Windows. But for most annoyances and anomalies caused by registry corruption, a quick rebuild will get you back to a smooth working system.

But what is the registry?
The registry is a database—an amalgam of two special files, SYSTEM.DAT and USER.DAT. These files are written to and edited much like any other database files, and just about any installation program will write to or edit them, although sometimes not as cleanly as we’d like. The "garbage in, garbage out" principle applies here, as well—except in the case of the registry, the "garbage out" seems to manifest itself as one or more Windows problems.

Third-party registry utilities
Before I begin describing the rebuilding process in detail, let me state that I know all about REGCLEAN and other Windows utilities that are supposed to cure registry ills. However, these programs work only if you can boot into Windows. Even then, Windows is using the very registry we're trying to clean. To me, this is like working on your car's engine while you're driving. Instead, we're going to clear things up another way. We're going to do it from DOS.
Warning: The following article involves editing your system registry. Using the Windows Registry Editor incorrectly can cause serious problems requiring the reinstallation of your operating system. TechRepublic does not and will not support problems that arise from editing your registry. Use the Registry Editor and the following directions at your own risk.
Using REGEDIT in DOS
The utility we're going to use is REGEDIT.EXE—the same REGEDIT that we use in Windows also runs as a DOS program. REGEDIT.EXE supports command line arguments that allow us to do a complete registry rebuild, while leaving the "dirt" and empty spaces behind. We'll eliminate the need to repetitively type commands by creating four batch files that you can carry with you and run from a floppy.
For the sake of simplicity, we'll assume that SYSTEM.DAT, USER.DAT, and REGEDIT.EXE reside in the C:\WINDOWS directory.
Step one: Remove the ReadOnly and Hidden attributes from SYSTEM.DAT and USER.DAT
The first step in rebuilding the Windows registry from DOS is to remove the ReadOnly, Hidden, and System attributes from the SYSTEM.DAT and USER.DAT files. A batch file that allows you to toggle the attributes off and on at will (REGATT.BAT) looks like this:
@echo off
if not "%1"=="-" if not "%1"=="+" goto INSTRUCT
attrib %1r %1h %1s c:\windows\system.dat
attrib %1r %1h %1s c:\windows\user.dat
goto ENDIT
:INSTRUCT
echo.
echo You must specify a - or + parameter, as in "%0 +" or "%0 -"
:ENDIT
echo.

To use it, enter the command REGATT - or REGATT + to remove or add the file attributes, respectively.

Here's how REGATT.BAT works:
  • @echo off: Prevents the lines that follow from being displayed on the screen while the commands are being executed. The "@" prevents "echo off" from displaying.
  • if not "%1"=="-" if not "%1"=="+" goto INSTRUCT: This makes the batch file look for one parameter and limits the parameter choices to either "-" or "+." If neither is found, the script jumps to the INSTRUCT portion of the batch file. Note the use of the double "equals" signs (==).
  • attrib %1r %1h %1s c:\windows\system.dat: Runs the "attrib" command on SYSTEM.DAT with either "-r -h -s" or "+r +h +s," depending on the parameter.
  • attrib %1r %1h %1s c:\windows\user.dat: Runs the "attrib" command on USER.DAT the same as it does for SYSTEM.DAT.
  • goto ENDIT: Jumps over the INSTRUCT statement since all went well.
  • :INSTRUCT: Label that identifies this portion of the batch file.
  • echo.–: Prints a blank line on the screen. Note that there is no space between "echo" and "."
  • echo You must specify a - or + parameter, as in "%0 +" or "%0 -": Instructions for using the batch file. The %0 is a variable that is automatically replaced by DOS with the name of the batch file you typed on the command line. If you typed regatt in lower case, the line will read "You must specify a - or + parameter, as in regatt + or regatt -." If you change the name of the batch file to "wom.bat" and type WOM in upper case, it will read "You must specify a - or + parameter, as in WOM + or WOM -" without further editing. Neat, huh?
  • :ENDIT: Label that identifies this portion of the batch file.
  • echo.: Prints a blank line on the screen before returning to the prompt.

Step two: Create a backup of SYSTEM.DAT and USER.DATThe rebuilding process effectively destroys the current registry. If the rebuild fails (I've seen it happen when the DAT files are badly corrupted), there will be no registry. Having a corrupted registry to restore is better than having no registry at all.
To make a backup, we simply copy the "unattribbed" SYSTEM.DAT and USER.DAT files with REGBACK.BAT:
@echo off
if "%1"=="" goto INSTRUCT
copy c:\windows\system.dat c:\windows\system.%1
copy c:\windows\user.dat c:\windows\user.%1
goto ENDIT
:INSTRUCT
echo.
echo You must enter a 1 to 3 character file extension, as in "%0 sav"
:ENDIT
echo.

Most of the lines in REGBACK.BAT are similar to those in REGATT.BAT. The three unique lines are:
  • if "%1"=="" goto INSTRUCT: This jumps to the INSTRUCT section if no parameter is given after the "regback" command. Without a parameter, the value of %1 is null, so the statement translates to if ""=="" goto INSTRUCT and, since double-quotes indeed equal double-quotes, the script jumps to give the user instructions.
  • copy c:\windows\system.dat c:\windows\system.%1: Copies SYSTEM.DAT to SYSTEM.parameter. Be sure to limit your parameter to three allowable DOS characters.
  • copy c:\windows\user.dat c:\windows\user.%1: Copies USER.DAT to USER.parameter as above.

Step three: Rebuilding the registryDO NOT ATTEMPT TO RUN THESE COMMANDS UNLESS YOU HAVE MADE BACKUP COPIES OF SYSTEM.DAT AND USER.DAT! Remember, you will destroy the existing copy of the registry in the rebuilding stage. If the rebuild fails, so will you. Be sure you have your own backup.
REGREBLD.BAT looks like this:
@echo off
echo.
echo Exporting registry contents. Please wait...
regedit /l:c:\windows\system.dat /r:c:\windows\
user.dat /e c:\windows\newreg.reg

echo Rebuilding the Windows registry. Do not interrupt!
regedit /l:c:\windows\system.dat /r:c:\windows\
user.dat /c c:\windows\newreg.reg

echo.
del c:\windows\newreg.reg
echo.

REGREBLD.BAT takes no parameters. Here's what the crucial lines do:
  • echo Exporting registry contents. Please wait...: The REGEDIT "export" command displays no information while it's executing. This is a courtesy line to let you know that something is happening.
  • regedit /l:c:\windows\system.dat /r:c:\windows\user.dat /e c:\windows\newreg.reg: Exports the contents of the current registry to a file we'll call "newreg.reg." The "/l:" and "/r:" switches point to the exact paths of SYSTEM.DAT and USER.DAT, respectively. The "/e" switch is for "export" and "c:\windows\newreg.reg" is the name of the target file that is created during the process.
  • echo Rebuilding the Windows registry. Do not interrupt!: Another courtesy statement. Unlike the "export" command, the REGEDIT "create" command displays a progress counter. However, it doesn't state what it's creating, only that it’s importing.
  • regedit /l:c:\windows\system.dat /r:c:\windows\user.dat /c c:\windows\newreg.reg: Creates a new registry from the contents of "c:\windows\newreg.reg." The key here is the "/c" switch, for "create." As soon as it is encountered, the current SYSTEM.DAT and USER.DAT are destroyed as new files are created from the data in newreg.reg. If this process is interrupted, the new registry will be incomplete and, therefore, useless.
  • echo.: The progress counter that is displayed by REGEDIT does not have a carriage return. This statement forces one at the completion of the "create" process.
  • del c:\windows\newreg.reg: Deletes the now unnecessary newreg.reg data file. You can remove this line if you want to look at the contents of newreg.reg before you delete it manually.

The full export/create routine can be quite time-consuming, depending on the size and state of the current registry. I've seen it take anywhere from five minutes to over an hour to rebuild the registry on desktop PCs. I don't recommend using it on laptops. If the rebuilding is successful (and most of the time it is), you won't need the next step.

Step four: Restoring a failed rebuild
Step four involves returning the registry to its previous state in the event a failed rebuild leaves you without working SYSTEM.DAT and USER.DAT files. We'll call this batch file REGRET.BAT. Remember the extension you used when creating your backups? You'll need it here:
@echo off
if "%1"=="" goto INSTRUCT
if not exist c:\windows\system.%1 goto NOFILE
if not exist c:\windows\user.%1 goto NOFILE
attrib -r -h -s c:\windows\system.dat
attrib -r -h -s c:\windows\user.dat
del c:\windows\system.dat
del c:\windows\user.dat
copy c:\windows\system.%1 c:\windows\system.dat
copy c:\windows\user.%1 c:\windows\user.dat
goto ENDIT
:NOFILE
echo.
echo Cannot locate one or more of your "%1" backup files!
echo Please verify your file extension and try again.
goto ENDIT
:INSTRUCT
echo.
echo You must give a valid backup file extension, as in "%0 ext"
:ENDIT
echo.

REGRET.BAT runs by entering “regret ext” at the prompt, where “ext” is the extension you used when creating your backups. If the ext files aren’t found, REGRET tells you. All of the REGRET commands are similar to ones we've used in the previous batch files. Note that after we delete the failed SYSTEM.DAT and USER.DAT files, we copy the backups to the DATs as opposed to renaming the backups. I never feel comfortable deleting critical backup files until I'm absolutely sure they won't be needed again. Delete them manually when you are comfortable.

Use what you’ve learned
Now that you have your batch files, go ahead and try them on a sick system. Boot the PC to a true DOS "Safe mode command prompt only" and run the files from a floppy. If you make the floppy bootable, be sure that you have an AUTOEXEC.BAT that contains a path statement pointing to C:\WINDOWS;C:\WINDOWS\COMMAND. A successful rebuilding of the registry will solve many of your "mysterious" Windows problems, including many Windows protection errors.
What do you think of the method for rebuilding a registry described here? Do you know of a better way to solve this problem? We want to know. Post a comment below or send us an e-mail.
  • Save
  • Print
  • Recommend
  • 6

Print/View all Posts Comments on this article

npike@... | 08/07/00
let microsoft do it y2troll@... | 08/13/00
How do you do this? stevenb@... | 09/15/00
reg rebuild using win98 CD SkiKatana | 01/11/01
Registry compromised. samplehead@... | 04/27/01
Did I Miss Something? Roger | 04/27/01
Registry compromised. Dear boyz & girlz k_a_hunter | 12/28/01
Huh? Hitman Geno | 12/29/01
Read closer dlanning | 12/31/01
Required parameter missingBad ... DaZed-n-fuzed | 12/31/01
Fixed it! DaZed-n-fuzed | 12/31/01
Installing Windows on top of itself galamb@... | 07/25/02
Jeezzz, By the time I've done all that mike.delmonico@... | 08/13/00
I'd like to see that... ktimm@... | 08/17/00
And that's just the basic installation tsrecord@... | 03/21/02
Great help but... msamson | 08/30/00
Microsoft vs Ford or GM bob.phinney@... | 04/05/01
Err...NO!!!! Anthropic Al | 05/01/01
Microsoft vs Ford or GM k_a_hunter | 12/28/01
Where was Bill? switcher | 07/24/02
Computer Voodoo DRMartin789 | 05/26/05
insightful lkerr@... | 04/07/01
college education dskoe@... | 12/26/01
You guys kill me! cjpearce@... | 07/24/02
gmh k_a_hunter | 12/28/01
Rebuilding The Registry jale@... | 09/14/00
I could not get Regrebld.bat to work dlanning | 12/29/01
The fix.... DaZed-n-fuzed | 12/31/01
Thanks for bringing this one Back!! northener | 07/25/02
No NTFS thom46@... | 07/20/05
Edit registery in dos jlklk@... | 01/25/06
Will this technique work with XP / Vista, and NTFS-Read boot disks? prophet777@... | 10/24/07
Dachsund Software's "Hare" prophet777@... | 10/25/07
Web page is down klein48@... | 05/15/08
doug_yates@... | 08/07/00
Revert to older versions of the registry damon.sas@... | 01/12/01
That works to a point oskiller@... | 04/27/01
restore old registry k_a_hunter | 12/28/01
To restore the registry Drew Peacock | 09/04/01
blackquestor@... | 08/07/00
How can you use bad registery? Mohammed I | 12/23/00
How does this work? Answer here! Roger | 04/27/01
Do it yourself, Mohammed famosamos | 04/27/01
linda.losik@... | 08/07/00
Yep ERD does save the day gutoi@... | 04/27/01
Stephen Gelman | 08/07/00
Why not a laptop? Read here to find out! Roger | 04/27/01
DisillusionedMember | 08/07/00
Doesn't always work frank_w44@... | 08/15/00
bdlang@... | 08/16/00
rathamon | 08/07/00
scanreg, i agree nikallen@... | 04/27/01
david.emerson@... | 08/07/00
hugs@... | 08/07/00
fox137@... | 08/07/00
webSchmidt | 08/07/00
ravuj | 08/07/00
98's Scanreg won't do it? bebopwulf | 09/05/00
robinarm | 08/07/00
reggie_knowlton@... | 08/08/00
Works well, but needs more help Xerxesix | 09/08/01
reggie_knowlton@... | 08/08/00
Win2k Add/Remove Programs Applet DMac | 09/19/00
and the 98 version.... mindtrick | 01/12/01
brucet@... | 08/08/00
John Appalling | 08/08/00
The point is... raintree | 08/17/00
Dedw8 | 08/09/00
wizardmg@... | 08/09/00
g_zollar@... | 08/09/00
graeme.dundee@... | 08/09/00
CSA | 08/10/00
stw@... | 08/10/00
sean0u@... | 08/10/00
wolfgang@... | 08/11/00
jimfalls@... | 08/11/00
What? No download file? jbarta@... | 08/13/00
Re: No Download File? tspace@... | 08/14/00
Reg Repair leart2@... | 08/17/00
Copy & Paste DisillusionedMember | 08/30/00
Copy & Past - in DOS ? tspace@... | 09/06/00
wbchaney | 04/27/01
how are you reading ... oded@... | 07/24/02
Bad Typist! Me too: Easy remedy lcagle@... | 11/29/00
Look, ma! No Typing! wbchaney | 04/27/01
chief@... | 08/11/00
Lame? DisillusionedMember | 08/30/00
kalkjagd@... | 08/12/00
Phew! Time Consuming! rjb9@... | 08/13/00
Time Consuming? tollhsecraka@... | 04/05/01
Very Well said !!! transistor62 | 07/27/02
kalkjagd@... | 08/12/00
Great Tip! WardSysAdmin | 08/14/00
Registry all inclusive mstrong@... | 09/06/00
Fantastic Material TJirak | 08/14/00
It works! cindy.watson@... | 09/05/00
Will it work with win2000 Mohammed I | 12/23/00
Re: Will it work with win2000 justin.hooper@... | 12/26/00
W9x only! mph@... | 01/12/01
No Brainers... Brother Rain | 04/23/01
Anthropic Al | 05/01/01
scanreg k_a_hunter | 12/28/01
Better way jimbrubaker | 01/22/02
Prerequisite for scanreg/restore C_Tharp | 07/25/02
does this work tgamac1he@... | 03/22/02
If the registry files are damaged... borfig | 03/23/02
if registry files are damaged oded@... | 07/24/02
Gr8 thing to explain but.... dominatorpk@... | 03/25/02
superb rkarthik3k@... | 04/08/02
use system safe gold. nomala@... | 07/23/02
Excellent article ! necromanthus | 07/24/02
What's wrong with using..... Al Guzman | 07/24/02
Regrebld did what scanreg didn't dlanning | 09/09/02
How long should this take? spcole | 07/31/02
It took a long time dlanning | 09/09/02
regrebld.bat tronix@... | 08/13/02
You need to add a path statement dlanning | 09/09/02
RE: Learn to rebuild the Windows registry from DOS jbuddah1@... | 11/02/07
RE: Learn to rebuild the Windows registry from DOS b1zki7 | 06/02/08

What do you think?

White Papers, Webcasts, and Downloads

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET

Product Spotlight

advertisement
Click Here