views:

97

answers:

4

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?

+1  A: 

I haven't tried this, but I can think you can write to the Windows' Registry at installation time and read it at runtime.

Jader Dias
That is the general way of doing it, write-to/read-from either registry/database/config file. Registry is a good common location for both the application and upgrade/uninstall to access. Technically I think the registry in certain instances could be locked down so an app couldn't read, but I haven't really ever ran accross a setup like that.
Rob McCready
+2  A: 

You could pass the provided location to a custom install action and do whatever you wanted with the value that the user provided your custom installer action with. Save to text file, config file, registry, whatever...

Just pass the value that the user selected through CustomActionData to your custom install action and read it in during OnInstall.

http://msdn.microsoft.com/en-us/library/2w2fhwzz%28VS.80%29.aspx provides detail how to pass data into your custom install action.

Then when you launch your application you can just read from the known location whatever it may be.

Wil P
As far as I understood, the CustomActionData enables the installer to receive data from the command line.
Jader Dias
Studying a little more I found that a Setup Project can pass data to a Primary Output, if it is a Installer Class, using CustomActionData. As you meant.
Jader Dias
Sorry I wasn't more clear on that earlier, I looked for a good example of a custom installer class to associate to your custom action but couldn't find a good one quickly enough. Regardless they are pretty easy to setup.
Wil P
I couldn't make it arrive at the app.config file. More on http://stackoverflow.com/questions/1591725/how-do-i-alter-a-net-application-user-settings-on-installation
Jader Dias
If you can get the app.config file open in the right path you should be able to apply the setting using the System.Configuration namespace. Typically what I will do when using an installer class in this case is use a location relative to the Assembly.Location where the installer class is defined since the process running the installer is msiexec.
Wil P
All changes that I do to the Settings are discarded after the install. It doesn't even generate a user.config file.
Jader Dias
A: 

There is a couple of ways ...

  • the installation program can write a config file in a certain location that can then be read by the application (typical for older windows versions and linux variants)
  • for windows programs, the registry is the preferred way of writing and reading such information (until MS comes up with a new way of doing these things). Every application gets a "typical" path in the registry, and can read write to it. This does not only apply to information set by the user during the installation, but also a lot of config stuff.

Not sure what your question is aiming at, though .. It sounds like you have a specific scenario in mind.

IronGoofy
+2  A: 

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.

0xA3
Great tutorial!
Jader Dias
if you could also help me here: http://stackoverflow.com/questions/2066048/how-to-make-a-system-configuration-install-installer-to-get-a-variable-from-the-s
Jader Dias