I have an application where I'm implementing automatic updates. I have a web service that the program checks and if it needs to upgrade it downloads and runs the new installer (Visual Studio 2005 Setup Project), after which the program relaunches. All well and good.
But how do I make sure that the installation path in the installer defaults to the same path that the user originally installed the program to?
For example, if the user changed it from program files to C:\SomeFolder, how would I make the installer detect that and change it's install path to C:\SomeFolder instead of program files? Or if the user chose to install it for "Current User" instead of "All Users"?
-Right click the Setup Project
-View
-Registry
-In the left side, expand the HKey_Local_Machine and Software and click the Manufacturer node
-In the right side, right click and Add String registry key
-Name the registry key InstallDir
-Set its value [TARGETDIR]
.
After the program is installed you can see the InstallDir regkey contains the location. Your updater application can use this same path.
Generally the only difference between "Just Me" and "Everyone" is the location of the shortcuts that are created. You can run Process Monitor during an install and see for yourself.
EDIT:
The updater application can use the InstallDir RegistryKey with these steps. Ref: How to: Use a Registry Launch Condition to Specify a Target Directory
-Right click the Setup Project of your Updater
-View
-Launch Conditions
-Add a Search For RegistryKey
-Specify the Property as SEARCHFORINSTALLDIR
-Specify the RegKey as SOFTWARE\ManufacturerName
-Leave root pointing to HKLM
-Specify the Value as InstallDir
-Add a Launch Condition
-Specify the condition as SEARCHFORINSTALLDIR
-Leave InstallUrl and Message
-Right click the Setup Project
-View
-File System
-Select Application Folder
-Press F4 to view the properties of the Application Folder
-Specify the DefaultLocation as [SEARCHFORINSTALLDIR]
Now when you Build the Setup package for the Updater and run it, it will give you the value in the InstallDir regkey for the install path.
If you wish to disable the "Folder Textbox" and the "Browse" button to prevent users from changing the updaters install path you can use Orca.exe. Orca is a database table editor for creating and editing Windows Installer packages and merge modules. Then simply follow this setup project, fixing the location of installed kit
Another way you could do this is following Aaron Stebner's How to modify the default install path in an MSI-based setup based on a registry value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With