The registry associates file extensions with file types and their applications.
Taking Visual Studio as an example, the key HKCR\.sln points to the file type VisualStudio.Launcher.sln (HKCR being the abbreviation for HKEY_CLASSES_ROOT).
Under HKCR\VisualStudio.Launcher.sln\Shell, the registry lists all commands that are available from Explorer’s context menu on a .sln file.
I investigated how to add my application to this key using a Visual Studio Setup Project (.vdproj), especially, how to retrieve the installation directory selected by the user during setup.
In the Registry view of the Setup Project
- locate the HKEY_CLASSES_ROOT key.
- select New Key and add the file type, e.g. VisualStudio.Launcher.sln.
- select New Key, and add “Shell”
- select New Key, and add either “[ProductName]” or the text you want to display in the context menu
- select New Key, and add “Command”
- in the right-hand pane, Select New/String Value, and delete the name of the key. The name will now be displayed as “(Default)”.
- select the default key, go to the Properties window, and set the value to “[TARGETDIR]myprogram.exe” “%1”.
(The double quotes have to be typed in the property value to handle spaces in executable and document paths).
Upon installation, your program will now appear in the context menu of the files associated with this type.
The difficulty for me was to find the macros that can be used in a setup project. That’s because Microsoft does not refer to them as installer macros or installer variables, but rather properties.
Here is the complete list of Setup Project Macros.