Search code examples
.netvisual-studiosetup-project

Is there any way for a .NET application to read a variable defined at installation time?


With Visual Studio Setup Project I can ask for the user for some input, like a location of a folder. There is any way for the installed application to read the user input?


Solution

  • The simplest way to do that would be to store the value in the Registry:

    1. Right-click your setup project and select View -> User Interface

    2. Add a new dialog under Install and move it to the correct position within the sequence

    3. Each control in a dialog has a property called Property, e.g. Edit1Property or ButtonProperty. The name of this property should be some unique value, by default it will be something like EDITA1. We will use this property name later to refer to the value of the control.

    4. Right-click your setup project and select View -> Registry

    5. Navigate to HKCU\Software\[Manufacturer] or to HKCU\Software\[Manufacturer] depending on whether you want to store this setting for the current user only or machine wide. You can also create a new entry under User/machine hive. Then the entry will be stored either under HKCU or under HKLM depending on whether the installation is per-user or per-machine.

    6. Create a new value under the key selected in 5. In the properties view of that value enter the property name of the control that has been specified in step 3. This name has to be in square bracket, for example [EDITA1] and you are done.