The Windows Registry

Posted by: Xav in Untagged  on

A cold night
The Registry is a scary place, where secret settings and dangerous parameters are imprisoned... until you type "regedit" into the Run box, of course. Outside, a gale picks up, as you enter the HKEY_LOCAL_MACHINE hive. Suddenly, a huge blue monster appears and encases you. "Windows has encountered a problem and needs to close. Sorry for the inconvenienve." it says evilly. You shudder, and reboot. No sound. No light. Nothing. Your computer is ruined.

OK then, now we've got that out of the way. Many people think the Registry is a scary place, but it's actually very useful for storing application settings. However, the golden rule is: don't pollute the Registry! Many programs store unnecessary rubbish, and it all clogs the computer up. Make sure you have some sort of way to delete your entries if the program is uninstalled, otherwise they will remain there uselessly. And don't delete entries that aren't yours, because that's called a virus, ha ha.

What is the Registry?
The Registry is simply a place where Windows stores settings. Other programs can also store settings there, as a sort of large database.

The Registry is stored in what's known as a "hierarchical" structure - this means it is like a tree, with branches coming off them.

Data is stored in things called keys. A key is simply a setting. The actual value of the setting is stored in its values. The value can be one of these data types:

Data Type
Use
REG_SZ
 This is the main data type. Used for storing short text data (or fixed-length string data).
REG_EXPAND_SZ This type can store strings which change in length at runtime.
REG_MULTI_SZ This data type holds an array of strings, separated by a null character.
REG_BINARY Used to hold binary data.

The most common data type is REG_SZ, because it can hold anything, such as "Xav", "False", "86"... anything like that.

Hives
All the keys are organised into hives. These can be considered as large folders, containing the different keys. All keys must be inside a hive. Here are the hives used on a computer:
 Node Contains
HKEY_CURRENT_USERConfig info for the current user in Windows.
HKEY_USERS Data about all users on computer. HKEY_CURRENT_USER simply links to one of the profiles in HKEY_USERS.
HKEY_LOCAL_MACHINE Config info about the whole computer, regardless of who is logged in.
HKEY_CLASSES_ROOTInfo about the file types on the computer, and which programs are associated with them. Also contains data about COM components' configuration data.
HKEY_CURRENT_CONFIG Info about the hardware profile used during startup.

To see the structure of keys, hives and values, open the Registry Editor by typing "regedit" from a command prompt or via the Run command.

Where .NET comes in
As usual, the .NET Framework makes it easy for us. There exists a Registry object, which is statically placed within the My.Computer object. Therefore, to access it, we simply use My.Computer.Registry. Simple, eh?

You may be wondering about the "My" object. When Microsoft created .NET, many people were confused with the complexity of it all. Therefore, a "My" object was created, to link to some of the most commonly used functions. So, to access the Registry, for example, we use:

 
  1. 'Create a new key.
  2. My.Computer.Registry.CurrentUser.CreateSubKey("SaveOnExit")


However, this tutorial needs breaking up a little bit,  so look out for the next blog, which will describe exactly how to manipulate the keys and values using VB.NET.  You'll realise how easy the functions are, and in no time you'll be read ing and writing to and from the registry like a pro. Ta ta!

Trackback(0)
Comments (2)add comment

PlayaSkater said:

What types of things would you need to do in the registry (as far as adding new keys and hives and such)?
 
report abuse
vote down
vote up
July 13, 2008
Votes: +0

Xav said:

You cannot add/remove/edit hives. You can create keys (a bit like folders) under hives and other keys, then save data in values, which are a bit like files inside the key.
 
report abuse
vote down
vote up
July 15, 2008
Votes: +0

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

busy