2
votes

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

4 Answers

6
votes

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.

1
votes
1
votes

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.

0
votes

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.