2

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.

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316

4 Answers4

6

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
  • 66,094
  • 13
  • 157
  • 251
  • 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! – Dirk Vollmar Jan 20 '09 at 23:59
  • Thanks for your edit (and the funny remark ;). Raymond's posts are always a good read! – Dirk Vollmar Jan 21 '09 at 00:34
1

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?

Community
  • 1
  • 1
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
1

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.

saschabeaumont
  • 22,080
  • 4
  • 63
  • 85
  • 2
    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 – Dirk Vollmar Mar 10 '09 at 21:20
0

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
  • 33,834
  • 5
  • 90
  • 130
  • 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 Jan 22 '09 at 10:40
  • 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 – Dirk Vollmar Jan 22 '09 at 10:43
  • Oh, oops, I missed the fact that this was for *Office* templates. Sorry. – Rob Mensching Jan 22 '09 at 16:57