views:

4212

answers:

4

Using WiX (Windows Installer XML) I have created an MSI installer which installs Word templates into the users Application Data folder, e.g. on Windows XP

C:\Documents and Settings\<user>\Application Data\Microsoft\Templates

I'm retrieving the path to this folder from the registry:

<Property Id="APPDIR" Secure="yes">
    <RegistrySearch Id="RegSearch_AppData" 
        Type="directory" 
        Key="Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"    
        Name="AppData" 
        Root="HKCU" />
</Property>

<CustomAction Id="ActionWordTemplateFolderAssign" 
              Property="TEMPLATEFOLDER" 
              Value="[APPDIR]Microsoft\Templates" /> 

<InstallExecuteSequence>
    <Custom Action="ActionWordTemplateFolderAssign" Sequence="1" />
</InstallExecuteSequence>

However, some users installing the MSI file on Windows Vista receive an error because the APPDIR property is empty.

Is APPDIR not the correct way to retrieve the Application Data folder? Or do I have to consider another property on Vista?

EDIT: This is just a short version of the WiX Code to retrieve Word's template folder. First I'm actually checking whether the user has a custom template folder defined by a policy or under HKCU\Software\Microsoft\Office\12.0\Common\General\UserTemplates. However, if none of these are set the fallback is to use the default location under %APPDATA%\Microsoft\Templates which is retrieved by the above code.

+4  A: 

You should use [AppDataFolder] instead. I can't find anything about "appdir" in the windows installer property reference.

Edit after question edit: The shell folders key (great blogpost btw) where you get your appdir value from is a very old and deprecated way to get at the system folders. It is only there for backwards compatibility and you should not rely on it. Especially if you live near Raymond Chen.

Edit 2: Since the real question turns out to be "how do I find the user's word template folder"... The word template folder is not always

[AppDataFolder]\Microsoft\Templates

This is because the template folder can be configured under tools - options - file locations - user templates. Ironically we are back to searching the registry if we want to detect this:

  <Property Id="USERTEMPLATES">
     <RegistrySearch Id="SearchUserTemplates"
             Root="HKCU"
             Key="Software\Microsoft\Office\11.0\Common\General"
                 Name="UserTemplates"
             Type="raw" />
  </Property>

This registry value is normally not present however, and you cannot specify a default value that contains [AppDataFolder] here (I tried).

Instead, I would try to define two components, one which installs to USERTEMPLATES and one which installs to [AppData]\Microsoft\Templates. You can then make use of Condition elements to test for the existence of USERTEMPLATES, and install only the right one.

Wim Coenen
Sorry, I overlooked that the APPDIR property originates from the Registry, my mistake. How come this doesn't work on some (localized?) Vista installations? I'm trying your suggestion as it sounds really helpful and keep you informed. Thanks!
0xA3
I've edited my answer to shed some light on this.
Wim Coenen
Thanks for your edit (and the funny remark ;). Raymond's posts are always a good read!
0xA3
+1  A: 

Some additional information:

The reference for MSI properties containing special folders:

http://msdn.microsoft.com/en-us/library/aa370905(VS.85).aspx#system_folder_properties

And a link to a related blog post:

http://stackoverflow.com/questions/199173/what-is-the-wix-equivilent-of-environment-specialfolder-applicationdata-from-net

0xA3
+1  A: 

Divo - In response to your comment on localized Vista installations, the problem probably isn't so much localized Vista (unless I'm reading you wrong) but localized Office.

Microsoft\Templates might become Microsoft\Vorlagen with German office for example. It's a pain in the ass, because I haven't found a reliable source of documentation on what folder names have been localized in Office, and what haven't.

My particular problem was with installing Macros to [AppDataFolder]Microsft\Word\STARTUP - which is localized for some languages only. #$%# in the end we just get customers to manually move the templates, the majority of our markets don't have a problem but we've noticed Italian and Turkish office plus a couple of others seems to exhibit this rather annoying behaviour.

sascha
I think the localized name of the template folder is stored in the registry under HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\General\Templates
0xA3
A: 

On Vista there is a new standard folder available called TemplateFolder. I think that is what you want. To use it in WiX just do something like:

<DirectoryRef Id="TARGETDIR">
   <Directory Id="TemplateFolder" Name="Templates"/>
</DirectoryRef>

Then you can reference the TemplateFolder Directory where ever you may need it.

Rob Mensching
Interesting, but this installs to C:\Documents and Settings\user name\Templates. Word does not appear to notice templates which are put there. Not sure what this folder is for.
Wim Coenen
Yes, this is the general templates folder used e.g. by Explorer's File -> New command. Word templates unfortunately don't use this folder but use a custom per-user folder, typically %APPDATA%\Microsoft\Templates
0xA3
Oh, oops, I missed the fact that this was for *Office* templates. Sorry.
Rob Mensching

related questions