The registry is the master database file in Windows operating systems that keeps tracks of
everything about every installed program.
Registry Corruption and Repair
The structure of the registry is complex. It tends to become corrupted, and filled with deadwood. An entire industry has
grown up to fix the damage. For most people repairing such damage with as little fuss as possible is all they ever do
with the registry. For that see the entry on registry fixers
RMI Registry
Java RMI has a program called the registry (no relation to the Windows registry) for tracking
remote objects. However, most people use the term registry to refer to a file in Windows
called the registry.
Backing Up The Registry
Ordinary backup programs cannot deal with backing up or restoring the registry since it is always locked and in use. All
you can do is extract the data from it, and feed it back transaction by transaction with regedit. Programs like Norton
Ghost can backup and restore the entire registry by running under DOS
where the registry is not used at all. Ghost is the only way I know of recovering from a fatally damaged registry. You
can backup/restore sections of the registry, provided the registry as a whole is intact, with code like this (which
saves the SET environment):
You can spawn such regedit code with Runtime.exec. In W2K, it dumps the file in 16-bit big-endian
Unicode. If you try to read it with an ordinary 8-bit editor it will show every second
character as null.
Physical Location
The following information is not much practical use since you cannot edit the registry or even back it up with
conventional tools. I tell you this just to satisfy your curiosity and so you can get a rough idea how fat your registry
has become:
- In W95/W98/Me, the
registry is contained in two hidden files in your Windows directory, called USER.DAT and SYSTEM.DAT.
- In NT/W2K/XP/W2K3,
the registry is stored in several hives, located in the \windows\system32\config
and \Documents and Settings\{username} folders. One major chunk is called NTUSER.DAT
which contain the HKEY_CURRENT_USER hive. Two other major chunks are called software
and system.
Exploring The Registry
If you dig around the registry with regedit, you will see terrifying data values to keys such
as {098f2470-bae0-11cd-b579-08002b30bfeb}. These are not encoded data. These are just
random strings of gibberish, hopefully unique, used to index some other part of the tree. All links are symbolic, and
these are the sort of names used when a human has not taken the trouble to assign an intelligible name to the link, or
when the name of the link is effectively a digest. Sometimes you will find a link to a link using this cumbersome
mechanism. Unfortunately you cannot change them to intelligible names since they are also hard coded into various
programs.
You can learn quite a bit about how the registry handles java just by searching for strings like java,
JavaSoft, java.exe, javaw.exe, javaws.exe,
jnlp, jar, jdk, jre,
J:\Program Files\java\jdk1.6.0_14
or 1.6.0.
You could use regedit to look at HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft
to see this as a small tree of fields. If it is damaged, and you don’t have a backup, you could patch it field by
field, or use the text above to create phony registry section backup, convert it to the encoding your version of regedit
expects, and restore that, and then fine tune the result.
Alternatively, if the registry is a real mess, you could uninstall all java JREs and JDKs, delete all the files for the
JREs and JDKs, delete the HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft registry tree, and start
from scratch.
Useful Registry Locations
| Useful Registry Locations |
| Registry Location |
Use |
| HKEY_CLASSES_ROOT\Applications |
has pointers to java.exe and javaw.exe. You may find they are
screwed up pointing to old versions that no longer exist. This is where the Java Control Panel keeps track of which java.exe
to use. This sets up the shell command launchings. |
| HKEY_CLASSES_ROOT\CLSID\{CAFEEFAC-…} |
misc Java entries. |
| HKEY_CLASSES_ROOT\jarfile\shell\open\command |
controls the association for *.jar files. I like to set mine up to java.exe not javaw.exe
so I can see the error messages. I change it to: "C:\Program Files\java\jre6\bin\java.exe"
-jar "%1" %*. Ditto htmlfile. |
| HKEY_CLASSES_ROOT\JavaWebStart.isInstalled |
Is JWS installed? |
| HKEY_CURRENT_USER\ENVIRONMENT |
User-specific set environment |
| HKEY_CURRENT_USER\Software\JavaSoft\Prefs\com\mindprod\replicator where the package
name is com.mindprod.replicator. |
One place whereJava persists User Preferences. |
| HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Programs\Sun
Microsystems |
where installers track registration information about each product. |
| HKEY_LOCAL_MACHINE\SOFTWARE\Javasoft |
Are of most interest to Java programmers. Points to where the JDKs, JREs and Java plugins are
installed. |
| HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion |
should be set to 1.6, the version of
the currently active JDK/JRE. Note you need both the generic 1.6
and specific 1.6.0 entries. |
| HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs\com\mindprod\replicator where the package
name is com.mindprod.replicator. |
Where Java persists System Preferences. |
| HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft Windows\CurrentVersion\Uninstall |
tracks all the uninstallable programs, including the JDK and JRE. To get rid of a program from the registry
that has already been uninstalled, just delete the key and all its subkeys in this section. |
| HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\AdvancedOptions\JAVA_SUN\SELECT |
Where Microsoft’s browser, Internet Explorer, keeps track of which version of Java it uses. |
| HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\javaws.exe |
where javaws.exe is installed. See below for how this
auxiliary path mechanism works. |
| HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders |
where installers, including the JRE and JDK installers, keep track of what is already installed. If these
entries point to applications that no longer exist, they can block reinstallation. |
| HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products
autorun |
where the registry tracks which programs are autostarted on boot. |
| HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run dlls |
DLLs that are started on boot |
| HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs |
This section tracks shared DLLs. Often these point to shared files (usually DLLs but not always) that are no
longer there. You can delete such entries. Registry cleaning utilities do this automatically. |
| HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment |
system wide set environment |
| HKEY_USERS\usernamexxx\Software\JavaSoft\Prefs\com\mindprod\replicator
where the package name is com.mindprod.replicator. |
Another place where Java persists User Preferences. Does not appear in Vista. |
Note the registry is not stored purely alphabetically: HKEY_CLASSES_ROOT, HKEY_CURRENT_USER,
HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG.
The Auxiliary Registry App Paths
The registry also acts like an auxiliary path to help find the executable to load. There are a pair of entries:
one to define the executable and one to define the start directory:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe
(default) =
F:\Program Files\firefox\firefox.exe
path = F:\Program Files\firefox\
These entries tell windows where to find various programs as if they were on the path. By inserting an entry here for
your exe, you make it globally accessible. You could for example give a French name for the
user that mapped onto an English program name, or give a program several aliases, one key for each alias, all pointing
to the same program.
If you use 4NT/TakeCommand, you can just type the name of any program in this auxiliary
list with or without the .exe to invoke it. However, the default cmd.exe
command processor will not do this for you. However, if you invoke the program on the with NT/W2K start ⇒ run or Vista start ⇒ all programs ⇒
accessories ⇒ run, the program will launch.
It is a good idea to prune this region of the registry of deadwood. It gets filled with references to non-existent
programs during failed installs and uninstalls.
Installers are sometimes too timid/stupid to fix broken entries. I found, for example, that Opera would not launch
properly when I typed Opera on the command line. I discovered a registry entry in this region
was pointing it to an old version of Opera that was no longer installed. I patched the entry with regedit to point to
the new name and off it went. Registry cleaners will automatically purge broken entries of this type, but they won’t
repair them. Sometimes purging is enough. The next install might recreate it.
Java and the Registry
Java.exe looks in the registry to decide which version of Java to use. It can help to
delete or replace the file C:\WINNT\System32\java.exe which is often out of date.
It is wise to take a snapshot of the java portion of the registry. Then when it is later inevitably damaged, you can
restore it. Without such a backup you must either manually patch the registry or uninstall all your JDKs, JREs, JWS etc
and reinstall from scratch.
regedit /E C:\ENV\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft"
You can restore it with:
C:\ENV\java.reg
The exported registry is often in 16-bit Unicode. You may have to translate it to your native encoding
if you want to view it. You don’t have to view it unless you are curious. If you do you will see something like
this:
How Java Finds its Executables
Just to keep you on your toes, Java uses three differerent mechanisms to find its executables.
- Java Web Start uses the registry auxiliary Apps Path technique. You will find an entry in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths for javaws.exe pointing it to the javaws.exe it
will use if you just type javaws on the command line where there is no javaws.exe
on the path.
- java.exe uses a different mechanism that uses an extra C:\Windows\System32\java.exe
(which is on the path) that examines the registry to find the currently active JRE, and hence the official copy of java.exe.
- Just for variety, javac.exe just uses the plain old path to find the executable, though of
course you are free to set up an App Paths entry manually with regedit.
Manipulating the Registry
Staring with JDK 1.4 you can store information in the Windows registry in a platform-independent way using the
Preferences class. On other platforms this is implemented sanely with an SQL
database.
The Preferences feature of Java uses the Windows registry to store configuration information.
This does not give you general access to the registry however. I take it Sun was too cheap to buy/write some disk-based
BTree code or a simple SQL engine to handle this with ordinary files that could be easily backed up and restored.
For earlier JDK’s IBM’s Install Toolkit for
Java includes classes for doing registry manipulation. Giant Java Tree also has a set
of classes. NevaObject has a coroutine class
for calling Windows APIs. JConfig does not support registry operations because JConfig
is cross platform, and Windows is the only OS with this idiotic contraption.
Nodes in the registry can have an optional name/key for direct lookup, and an optional value. For nodes with keys,
accessible via direct name lookup, the associated value is called the data. For nodes without
keys, only accessible as a subnodes of some other node, the associated value is called a value.
Inserting a node without a key is referred to as inserting a value.
If you are developer, a more robust technique is to store your data in C:\Documents and Settings\User\Application
Data\ in ordinary flat files.
Poking The Registry With JNI
If you want to probe or poke the registry, you will need some JNI that implements some or all of Microsoft’s
registry API. Finding the documentation on how it works can take a while. Look for HKEY_TYPE
which defines the various sorts of value a registry key can have. You will need to implement SHGetValue
and SHSetValue as well as some of the 18 other methods. Trust Microsoft to make it is complicated
as possible. If you need such a JNI interface to the registry, I am available to create you light weight, special
purpose registry poker for a fee.
JNIWrapper Winpack
does many more native tweakings that access the registry.
Registry: Second Stupidest Idea In Computing
The registry is the second stupidest idea in computing. (DLL hell was the worst, both compliments
of Microsoft.) With the registry there is a single, shared, central file that all applications use to store their
configuration data in a convenient hierarchical format. The file has a complex delicate structure, which means you are
putting all your eggs in one basket. If it becomes corrupt, you lose the configuration information for all your
applications. Because it is so central to the OS, normally you can’t even restore it as a lump from backup,
without rebooting to DOS first. The registry becomes a performance bottleneck since different apps must wait in line for
access to it. There are so many negative consequences of having a central registry implemented as a single file, that I
have a hard time believing the true motives for creating the registry were not sinister. I suspect these were the true
motives:
Microsoft lock in
To make it more difficult to port Windows apps to operating systems without a registry. Microsoft wants to lock in
developers.
Piracy
To make it more difficult to backup and restore individual applications. You have to totally reinstall them from the
master CD. This discouraged piracy in the days before the CD burner. As a side effect, the registry harms legitimate
users trying to restore a corrupted application or trying to move it to a different partition. To move an application to
a different drive or partition, you must uninstall it, reinstall it, then manually reenter all the configuration options,
if you can remember them! If a customer has lost the key for an app or misplaced the master CD, or can’t
figure out which key goes with which disk, he can’t even reinstall. He has to buy a new copy of the
application. Hmmm.
Cover Up for Incompetence
To make it necessary to reinstall Windows every once in a while. If anything in the registry goes, novice users have
little hope but to reformat the disk and start over, and re-install Windows and all the applications. An ex Microsoft
employee told me that Microsoft coders do this as a matter of course each month. The registration keys are designed to
be easy to lose and hard to match with the corresponding CD. Legitimate owners of software end up rebuying unnecessary
copies of the products. Registration keys have no effect on pirates; they only harm legitimate users. Branding, in
contrast, would deter pirates.
Intercorporate Spying and Warfare
To make it easier to snoop on and meddle with your competitor’s configurations and file associations. In future
secure computer architectures, each application will run in an airtight sandbox where it cannot snoop on or meddle with
the files or programs of its competitors. The CPU will have a "dark room" where encrypted code is expanded
using the CPU’s private key. The code can be executed, but not examined by anyone. This will put an end to piracy.
There will be no more need for the idiotic registry. The only central unified registry needed will be a simple list of
apps and where they are. The slapdash extension association system will be replaced with a secure program association
set for each file.
Vendors should proudly advertise when their programs refrain from using the registry. I suggest something like to the no-all-eggs-in-one-basket
logo.
How could the registry be fixed. It need three major changes:
Separation
The OS assigns each application a hive — a mini registry. Applications can’t look
outside their hive, except read-only access to a deliberately public central hive. Only the app itself looks at its hive.
Normally, not even the OS peeks inside an application hive. As a result, the registry ceases to be a performance
bottleneck. It ceases to contain material irrelevant to the current purpose. It no longer requires contention to access
it.
Placement
The hive for an app lives in the directory for that app. If the hive becomes corrupted, only that app is harmed. If that
app is backed up and restored to any other machine, partition or directory it still works. The hive has no idea where it
is. Microsoft has to give up the idea of punishing legitimate application migration and restoration.
Robustness Through Automatic Restoration
There is a mechanism to publish a few public facts, e.g. the mime types of files the app is willing to display,
edit, print… (An app on its own cannot commandeer a MIME type from all other apps. It can merely get it self
added to list of potential associations). This structured public information is replicated centrally. If for some reason
the central registry becomes corrupt and loses these facts, the O/S can get them back by asking any hives it finds lying
about. It can thus recreate the damaged central hive from the public portion of the application hives. The OS is the
only entity that knows where an app is. Apps themselves don’t know where physically they are.
Books
 |
recommend book⇒Microsoft Windows Registry Guide |
| | paperback |
|---|
| ISBN13: | 978-0-7356-2218-0 |
|---|
| ISBN10: | 0-7356-2218-3 |
|---|
| publisher: | Microsoft Press |
| published: | 2005-09-14 |
| by: | Jerry Honeycutt |
| Covers XP registry, but not Vista. |
|