|
Home Command-Line Encarta Exchg and Outlook PDAs Windows Tips NT Tips Win2000 and XP Tips Registry FrontPg Extensions DataBase Router Info IE tips and tools Linux Wireless Home Owner Protection Keep Spam in check Windows XP tips Win Processes
Back to the Norris Home Page
| | 
Windows Registry Guide
(http://regedit.com). This site provides a handy list of Registry FAQ for NT and
Windows 9x

Rebuilding a Registry from Dos!
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.
| Before we begin... |
| 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.
| Please note the following |
| 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.DAT
| THIS IS NOT AN IDLE ADVISORY—THIS IS A CRITICAL
STEP! |
| The 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 registry
| Warning: Have you made your backup? |
| DO 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.
 Starting Registry Editor (Regedt32.exe)
There are two applications you will generally use when working with the Windows
registry—Regedit, which we just used to make a backup of the registry, and
Registry Editor (Regedt32.exe). Both have their strengths and weaknesses, but
for the following procedures, we will be using Registry Editor (Regedt32.exe)
exclusively. To run this application, click Start | Run, type regedt32
and click OK or press [Enter].
Setting the initial [Num Lock] position
To set the [Num Lock] key automatically to ON when Windows NT boots, open
Registry Editor and navigate to the following key:
HKEY_CURRENT_USER/Control Panel/Keyboard/
InitialKeyboardIndicators
Set this value to 2.
Hiding the last login user ID
When logging on to Windows NT, the user ID of the last successful logon is
displayed in the Login dialog box. To disable this so that no user ID appears,
open Registry Editor and navigate to the following key:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\
Current Version\WinLogon\
Add a new value called "DontDisplayLastUserName" as a REG_SZ data
type, with a value of 1.
Disabling CD-ROM Autorun
Windows NT automatically runs CD-ROMs placed in the CD-ROM drive. To disable the
CD Autorun feature, open Registry Editor and navigate to the following key:
HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/Cdrom
Set the Autorun value to 0.
Removing uninstalled applications from the Add/Remove
Programs box
Sometimes after uninstalling an application, it's not always removed from the
Add/Remove Programs box. The uninstall may have failed or just not finished. If
you then try to remove the program from the Add/Remove Programs box, you may get
an error message. If you know you've already uninstalled a program and need to
remove it from the Add/Remove Programs box, open Registry Editor and navigate to
the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
\Currentversion\Uninstall

Adaptive Menus in Windows 2000
Turning off the
menus iseasy; right-click the Taskbar, select Properties, and clear the Use
Personalized Menus
checkbox. Administrators can automate turning this feature on and off via the
registry.
1. Launch Regedit.
2. Open
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\.
3. Change the
value of the IntelliMenus entry to No.
You don't need to
restart the system. The change will occur when the
current user logs
out, then back on.

Hide the Network Neighborhood icon
Network users
frequently click around in Network Neighborhood, either
to find a
particular resource or just to see what's there. A great deal
of network
browsing can create something of a traffic jam by causing
master browsers
and backup browsers to repeatedly build resource lists.
Of course you can
ask users to keep their network browsing to a
minimum, but
realistically speaking, how effective is that? If you
really want to
prevent curious users from loitering in Network
Neighborhood,
consider hiding the Network Neighborhood icon.
There's a registry
change you can make that will prevent the Network
Neighborhood icon
from being displayed. Simply open the Registry
Editor and
navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\
CurrentVersion\Policies\Explorer
and add a DWORD value named
NoEntireNetwork.
Set that value to 1. (The default is 0 if the value
already exists.)
Save your changes and restart your system.
All your network's
resources will still be available through UNC or net
commands, but only
the users who really need them are likely to access
them that way.

|