views:

256

answers:

2

OS: MS Windows XP Pro (SP3)

My application needs to access external databases, the locations of which I specify on installation. The specified file paths are then written to the registry, and the application then pulls this information out of the registry when it needs to. I have implemented this in WiX as follows, using just one of the file paths as an example:

1) I create a variable (for one of the file paths), called RootDir and give it a default string value of “C:\”

<?define RootDir="C:\"?>

2) I insert an extra dialog in the installation UI and have an edit box (among others) which will display the default file path above.

<Dialog Id="FilePathDlg" Width="370" Height ="270" Title ="xxx">
  <Control Id="RootDirEdit" Type="Edit" X="20" Y="72" Width="320" Height="18" Property="ROOTDIR" Text="[ROOTDIR]" />

3) I also have a component for creating the registry key where this string will reside

<Component Id="RegistryEntries" Guid="04AD0437-89E1-498c-85FF-EE180BEB53E0"> 
  <RegistryKey  Root="HKCU" Key="Software\xxx" Action="createAndRemoveOnUninstall">
    <RegistryValue Type="string" Name="xxx" Value="[ROOTDIR]" KeyPath="yes"/> 
  </RegistryKey>
</Component>

When the installer is run, the user can edit the edit box described in (2) to enter the desired file path (say “P:\”). This value is saved to RootDir and then when the registry entries are installed, the value is written to the registry.

So far, so good. This works, but the problem is that it only writes the user-specified value (in this example “P:\”) to the registry entry in the current user key of the user performing the installation. Since I want the application to be installed by administrators only (I have a condition to do this), obviously the user-specified file paths are only written to the administrator’s current user key.

I have a line which ensures that the installation is per machine, rather than per user (i.e. the value of ALLUSERS is 1):

<Package InstallerVersion="300" Compressed="yes" Platform = "x86" InstallScope="perMachine"/>

So although the installer creates registry keys for all users, the value of the user-specified variable remains on the default value (in this case “C:\”) for all the other users but changes to the specified value (P:) for the administrator.

Does anyone know how I can change this so that the user-specified variables are written to the current user key registry entries of all the users rather than just those of the administrator?

A: 

There is a way but I highly advise against it. It relies on windows repair to propogate the HKCU registry component to each users profile the first time they use your application. Think along the lines of how many times you've seen Microsoft Office ask for the CDROM the first time you use the program.

This belongs in HKLM and you should rewrite your application to accept it there. Additionally there are those that would say that configuration data doesn't belong in an installer and that you should get it at first run of your application instead. I don't actually go that far in my believes but it's something for you to consider.

Christopher Painter
A: 

Your installer should write to HKLM. Your app, on startup, should check for values in HKCU, and if they do not exist should be copied from HKLM.

Bryan Batchelder