Add Registry Key and Value into a Setup Project

Published on Tuesday, June 14, 2011

We have a case to create a Setup project for a Windows Forms project in the Visual Studio 2010, we need to write registry key and value when user install our software.

How to Add Registry Key and Value in a Setup Project?

1: Click your Setup project, you will see there is a Registry icon on the top of Solution Explorer window:

setupReg00

Click the icon, a registry window will appear as shown in the screenshot below. for our case, we are going to add key and value under the HKEY_LOCAL_MACHINE\Software node:

setupReg01

Right click on the Software node and select New –> Key to create a new key, you can create multiple sub nodes here;

setupReg02

For a value, you can set it like below. For our case, we need to set a directory, then we select String Value

setupReg03

Because we need the directory to be the same as our software installation directory, we set it as below:

"[ProgramFilesFolder][Manufacturer]\[ProductName]\Lib\WinForm\SymbolFactory"

If our Manufacturer = “Our Manufacturer” and ProductName = "Our Product", then the setting above corresponds to the following real path:

"C:\Program Files (x86)\Our Manufacturer\Our Product\Lib\WinForm\SymbolFactory"
setupReg04

Save the setting, rebuild the Setup Project, and try to run the Setup program, now we can see the Setup program can write the Registry key and value.