0

How to check in WiX (Product.wxs) if Office is installed in version 2010, 2013, 2016, 2019 or later? 2007, 2003 or older should be ignored (as if Office is not installed at all).

I'm aware of this question: C#: How to know whether certain Office 2003 or 2007 application is installed?, but don't know how to check and combine multiple conditions in WiX. I totally can't come up with anything beyond what's in the above question...

Thank you in advance.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Endrju
  • 2,354
  • 16
  • 23

2 Answers2

2

I would not do that. There are too many options how office can be installed nowadays. "Office 365" version that is installed with ClickToRun and not MSI as an example (and may use different registry keys), 32 vs 64 bit options, etc. User can even install office after installing your tool, or update office version later.

Instead, you could detect the version in your VSTO tool (use something like Application.Version for this). And simply give some error message if it's not the one your tool supports.

Check out this topic as well for an overview: How to detect installed version of MS-Office?

Rob Mensching
  • 33,834
  • 5
  • 90
  • 130
Nikolay
  • 10,752
  • 2
  • 23
  • 51
  • Have you tried using launch conditions before suggesting to avoid any checks? – Eugene Astafiev Jan 19 '23 at 12:38
  • 1
    If you are asking if I know what launch conditions are, then yes I do. I actually think skipping any checks is the best option, considering the variety of ways how office can be installed. Won't it be sad if your launch condition will block the user from installing you app with the latest Office 365 for example? – Nikolay Jan 19 '23 at 12:42
  • @Nikolay I need to detect if this is 32 or 64 bit to install a proper version of the addin. Then if this is Office 2003+ then your method may be the best option. The issue is when there's no Office at all, because there won't be anything to start and show the error message. I think I can use some custom code with WiX / Windows Installer to detect, maybe that'd be the best solution... I thought it can be a little easier... – Endrju Jan 19 '23 at 22:13
  • 1
    As far as I know, a VSTO add-in should work with both 32 and 64 version of the office, without any changes if compiled for "Any CPU". Also, probably there is no harm to install add-in for office without office (at least for me), and users are usually smart. – Nikolay Jan 19 '23 at 22:59
  • 1
    If you want to skip a check (and I understand why - complexity of various launch conditions) you need to add additional logic to the add-in's code to not load the business model in the non-supported version and hide the UI if necessary. That is also a bit of work. And who know what is better - to support multiple launch conditions in the installer or deal with the add-in's code. – Eugene Astafiev Jan 20 '23 at 09:16
1

You can use a registry search like shown in the following snippet:

<Property Id="OFFICEPATH">
  <RegistrySearch Id="OfficeReg" Root="HKLM" Key="SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot" Name="Path" Type="raw" />
</Property>

<Condition Message="This application requires Microsoft Office 2010. Please install Office then run this installer again.">
      <![CDATA[Installed OR (OFFICEPATH)]]>
</Condition>

Also you may consider using the Windows Installer APIs to find out if the relevant product/package/component codes are present on the machine. These can be done via P/Invoke calls.

Everything depends on which Office editions you need to support. There are Click2Run editions of MS Office that don't add the usual or necessary windows registry keys. In that case you need to have a special case for that, for example, if your add-in is for Outlook, you could check the following path in the windows registry:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\Common\InstallRoot\Virtual\VirtualOutlook

Read more about that in the Determine whether Outlook is a Click-to-Run application on a computer

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Won't this snippet only work for detecting Office 2010 (32 bit)? Also, windows installer API will only work if office is installed using windows installer? – Nikolay Jan 19 '23 at 12:32
  • I don't have any problems with such launch conditions for both Office supported platforms. – Eugene Astafiev Jan 19 '23 at 12:38
  • @EugeneAstafiev thank you, Office 14.0 is 2010. Now what if a user has Office 15.0 or 16.0? This is totally fine with my requirements. In other words, how to check using WiX that the version is 14.0 OR 15.0 OR 16.0? Thanks in advance. – Endrju Jan 19 '23 at 22:08
  • 1
    You need to add a registry search for each version and use the logical OR operator in the condition. – Eugene Astafiev Jan 20 '23 at 09:08
  • @EugeneAstafiev I'm starting getting it. I think I had a mental block on this technology. Thanks for your support. – Endrju Jan 21 '23 at 00:58