Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

Common Registry Settings

4.87/5 (41 votes)
13 Jul 2007CPOL6 min read 1  
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:

PropertyDescriptionReg Type
AuthorizedCDFPrefixThe update URL for the applicationREG_SZ
CommentsAdditional comments to be displayedREG_SZ
DisplayIconThe display icon of the installed program, usually automatically taken from install pathREG_SZ
DisplayNameThe display name of the installed programREG_SZ
DisplayVersionThe version of the installed program (displayed)REG_SZ
EstimatedSizeEstimated size of the entire programREG_SZ
HelpLinkURL for product supportREG_SZ
HelpTelephonePhone number for product supportREG_SZ
InstallDateInstallation dateREG_SZ
InstallLocationLocation of the installed programREG_SZ
InstallSourceLocation of source filesREG_SZ
LanguageLanguage of the programREG_SZ
ModifyPathThe path to a program's modification/repair fileREG_SZ
NoModifyTells Windows not to display a "Modify" option for the program. (0=true, 1=false)REG_DWORD
NoRepairTells Windows not to display a "Repair" option for the program. (0=true, 1=false)REG_DWORD
PublisherPublisher nameREG_SZ
ReadmeThe path to a README fileREG_SZ
UninstallStringThe path to a program's Uninstall fileREG_SZ
URLInfoAboutThe URL to the application/publisher's pageREG_SZ
URLUpdateInfoThe URL used to update information about the applicationREG_SZ
VersionThe version of the installed program (not displayed)REG_SZ
VersionMajorThe major version of the installed program (not displayed)REG_SZ
VersionMinorThe 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)