How to get Application Data folder/Word template folder in Vista

windows-installerwindows-vistawix

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.

Best Answer

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.

Related Topic