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

10,928

Solution 1

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.

Solution 2

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:

What is the WiX equivilent of Environment.SpecialFolder.ApplicationData from .NET?

Solution 3

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.

Share:
10,928
Dirk Vollmar
Author by

Dirk Vollmar

Follow me on Twitter @dirvo!

Updated on June 04, 2022

Comments

  • Dirk Vollmar
    Dirk Vollmar almost 2 years

    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.