4

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"?

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
John
  • 2,653
  • 4
  • 36
  • 57
  • 2
    If user chose to install for *Current User* only, other users will have to install a new copy because all files and registry entries go into the user's profile. These settings are not visible to other users of the system, as opposed to *All Users* installation. – Alexey Ivanov Jul 15 '12 at 15:33

1 Answers1

13

-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].

enter image description here

After the program is installed you can see the InstallDir regkey contains the location. Your updater application can use this same path.

enter image description here

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

enter image description here

-Add a Launch Condition
-Specify the condition as SEARCHFORINSTALLDIR
-Leave InstallUrl and Message

enter image description here

-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]

enter image description here

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

Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • And so I'd pass the target director to the MSI when I run it? Like Process.Start("Updater.msi", "TARGETDIR=" & InstallDir)? Cause that's the solution that I came up with on my own, except that I use the application's current directory. Is using the registry the better solution? – John Jul 16 '12 at 14:33
  • Hi @John, please check my edits - best to do a compare of the diff's and double check you dont have `""[TARGETDIR]\MyApp.exe""` as its just [TARGETDIR] now. – Jeremy Thompson Jul 17 '12 at 04:02
  • Wow... Very thorough. Thanks! – John Jul 17 '12 at 18:26
  • What if the registry value is empty or doesn't exist? For example, the "InstallDir" value doesn't exist of a first-time installation, so I want the "Folder Textbox" has a default location. What shall I do? – Doctor.Who. Sep 14 '16 at 06:05
  • You want the Install Folder location to be filled in yet you don't have the InstallDir regkey? Maybe find the Exe another way, this might help: http://stackoverflow.com/questions/26613336/find-if-3rd-party-software-is-installed-the-install-path-and-the-exes-name – Jeremy Thompson Sep 14 '16 at 06:20