Click here to Skip to main content
Click here to Skip to main content

Common Registry Settings

, 13 Jul 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Essential registry tips for programming, including registering your application with Windows and creating custom file types

Introduction

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: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall

For global users: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

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:

Property Description Reg Type
AuthorizedCDFPrefix The update URL for the application REG_SZ
Comments Additional comments to be displayed REG_SZ
DisplayIcon The display icon of the installed program, usually automatically taken from install path REG_SZ
DisplayName The display name of the installed program REG_SZ
DisplayVersion The version of the installed program (displayed) REG_SZ
EstimatedSize Estimated size of the entire program REG_SZ
HelpLink URL for product support REG_SZ
HelpTelephone Phone number for product support REG_SZ
InstallDate Installation date REG_SZ
InstallLocation Location of the installed program REG_SZ
InstallSource Location of source files REG_SZ
Language Language of the program REG_SZ
ModifyPath The path to a program's modification/repair file REG_SZ
NoModify Tells Windows not to display a "Modify" option for the program. (0=true, 1=false) REG_DWORD
NoRepair Tells Windows not to display a "Repair" option for the program. (0=true, 1=false) REG_DWORD
Publisher Publisher name REG_SZ
Readme The path to a README file REG_SZ
UninstallString The path to a program's Uninstall file REG_SZ
URLInfoAbout The URL to the application/publisher's page REG_SZ
URLUpdateInfo The URL used to update information about the application REG_SZ
Version The version of the installed program (not displayed) REG_SZ
VersionMajor The major version of the installed program (not displayed) REG_SZ
VersionMinor 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.

Screenshot - RegUninstall.png

Start-up

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:

Screenshot - RegStart.png

Open with

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:

Step 1

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.

Screenshot - RegOpen.png

Step 2

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.

Screenshot - RegFileType.png

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

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.

Screenshot - RegFile.png

Shell menus

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 (Default) value.

Screenshot - RegShellMenu.png

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 drive and folder keys in HKEY_CLASSES_ROOT, which involve the same steps as above.

Conclusion

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.

History

  • 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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

MatrixCoder
Software Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberDavid Nash5-Feb-11 16:31 
GeneralThanks PinmemberChuck141128-Sep-10 7:10 
GeneralVery nice!! PinmemberKenny McKee16-Dec-08 13:46 
GeneralAuthorization Pinmemberpaulnyc13-Aug-07 10:54 
GeneralRe: Authorization PinmemberMatrixCoder17-Aug-07 13:27 
GeneralRe: Authorization Pinmemberpaulnyc18-Aug-07 0:44 
GeneralRe: Authorization PinmemberMatrixCoder20-Aug-07 12:00 
GeneralRe: Authorization Pinmemberpaulnyc26-Aug-07 11:02 
General%1 vs %L Pinmemberantidemon7-Jun-07 2:22 
GeneralRe: %1 vs %L PinmemberMatrixCoder7-Jun-07 10:18 
Generalgood work Pinmemberpino.lassandro22-May-07 5:43 
GeneralRe: good work PinmemberMatrixCoder22-May-07 8:06 
GeneralVery useful! PinmemberADLER113-Apr-07 10:44 
GeneralI'll second that! Pinmemberwtwhite19-Apr-07 19:04 
GeneralVery handy! PinmvpHans Dietrich13-Apr-07 8:34 
GeneralRe: Very handy! PinmemberMatrixCoder14-Apr-07 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 13 Jul 2007
Article Copyright 2007 by MatrixCoder
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid