The Registry is a powerful part of the Windows operating system and is most valuable to programmers. For instance, you could have your application show up in Windows' Add/Remove Software or create your own file types. That is all done via the Registry and this article will show you how.
Registering your application
Let's start with the basics registering your application with Windows. By doing this, you can add your application to Windows' Add/Remove Software. There are two different keys for this, depending on how you want to register your application. That is, whether you want to register it for the current user only or for anyone who uses the computer (global).
For the current user:
For global users:
Now first you will create a sub key with the name of your program, i.e. "ExampleApp," and then add any of the following values:
|The update URL for the application||REG_SZ|
|Additional comments to be displayed||REG_SZ|
|The display icon of the installed program, usually automatically taken from install path||REG_SZ|
|The display name of the installed program||REG_SZ|
|The version of the installed program (displayed)||REG_SZ|
|Estimated size of the entire program||REG_SZ|
|URL for product support||REG_SZ|
|Phone number for product support||REG_SZ|
|Location of the installed program||REG_SZ|
|Location of source files||REG_SZ|
|Language of the program||REG_SZ|
|The path to a program's modification/repair file||REG_SZ|
|Tells Windows not to display a "Modify" option for the program. (0=true, 1=false)||REG_DWORD|
|Tells Windows not to display a "Repair" option for the program. (0=true, 1=false)||REG_DWORD|
|The path to a README file||REG_SZ|
|The path to a program's Uninstall file||REG_SZ|
|The URL to the application/publisher's page||REG_SZ|
|The URL used to update information about the application||REG_SZ|
|The version of the installed program (not displayed)||REG_SZ|
|The major version of the installed program (not displayed)||REG_SZ|
|The minor version of the installed program (not displayed)||REG_SZ|
There are many options available, but most programs only use the DisplayName, DisplayVersion, NoModify, NoRepair and UninstallString properties. Very rarely have I ever seen a program with more. In the end, you should have something similar to the image below, although you may decide to specify more properties.
Next is how to launch your program automatically during start-up. As previously, you can specify your application's start-up for either the current user,
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run, or for all users,
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run. This time, you will only have to specify one key named after your application. The value should be a string value of the path to your application, like so:
One of the biggest needs of a programmer is to allow the user to open a file in their program. For this process, there are two main steps:
Specify your application by defining a sub key in the
HKEY_CLASSES_ROOT\Applications key. Now you will name your key the same as your application file with the EXE extension, i.e. Example.exe. From here, you will create another sub key:
\shell\open\command. You will then specify your application's path in the
(Default) value, followed by any necessary parameters. You must also follow a standard: the path name and parameters must be together in double quotes followed by the "%1" verb. Windows substitutes this verb with the file path of the file you are opening. The "%1" verb must also be in double quotes and must be before any other parameters.
Next, you must find the file extension you want your program to be associated with. Extensions are located in the
HKEY_CLASSES_ROOT key. For this example, I will use a TXT extension. Then create the sub key
\OpenWithList under the file extension key and name your sub key the same name as your application file from the previous step.
The application file keys in the above two steps must match exactly. Otherwise, Windows will not be able to open the file correctly.
File association is similar to the "Open with" procedure. This time, however, you will create a sub key in the
HKEY_CLASSES_ROOT key with the same sub keys as the first step in the "Open with" procedure. It doesn't really matter what you name this descriptive key, but it's usually a description of the file type. For example, the TXT extension has an associated key named "txtfile." The only difference between this and the "Open with" procedure is that you will have an additional sub key named
DefaultIcon. Inside, you will specify the path of the icon you want the associated file, such as a text file, to have in the
(Default) value. You will then add your descriptive key to the
(Default) value of the file extension you want in the
HKEY_CLASSES_ROOT key, as created in the second part of the "Open with" procedure.
Finally, we come to the shell menus, which are similar to both the "File association" and "Open with" procedures. This time, we will use two keys depending on how you want your shell menu to be set up. Let's say you want to add a menu option called "Test" to a TXT file. You would go to
HKEY_CLASSES_ROOT\txtfile\shell. This key, as you have seen before, will contain a sub key named "open." You will basically follow the same steps as before: creating your menu option -- i.e. a sub key named "test" -- and another sub key in that named "command." In "test," you will add the command that you would like to appear in the Context Menu in the
(Default) value. In "command," you will add your application's path and the "%1" verb to the
Now if you want to add a menu item to any file associated with your program, you must repeat the above steps for your application's key, i.e.
HKEY_CLASSES_ROOT\Applications\Example.exe. If you want to add a menu option to a directory or drive, remember that there are always the
folder keys in
HKEY_CLASSES_ROOT, which involve the same steps as above.
The Registry can get confusing at times, but hopefully I have helped clarify it a bit. Just remember to keep a backup of your Registry settings and always be careful when editing keys. I am always open to more ideas and will be glad to add them to my article.
- April 13, 2007 - Original version posted
- May 16, 2007 - Added the "Shell menus" section
- July 13, 2007 - Article edited and moved to the main CodeProject.com article base