Does anyone know what would be the best way to detect which version of Office is installed? Plus, if there are multiple versions of Office installed, I'd like to know what versions they are. A bonus would be if I can detect the specific version(s) of Excel that is(/are) installed.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
One way to check for the installed Office version would be to check the
InstallRoot
registry keys for the Office applications of interest.For example, if you would like to check whether Word 2007 is installed you should check for the presence of the following Registry key:
This entry contains the path to the executable.
Replace 12.0 (for Office 2007) with the corresponding version number:
The other applications have similar keys:
Or you can check the common root path of all applications:
Another option, without using specific Registry keys would be to query the MSI database using the
MSIEnumProducts
API as described here.As an aside, parallel installations of different Office versions are not officially supported by Microsoft. They do somewhat work, but you might get undesired effects and inconsistencies.
Update: Office 2019 and Office 365
As of Office 2019, MSI-based setup are no longer available, Click-To-Run is the only way to deploy Office now. Together with this change towards the regularly updated Office 365, also the major/minor version numbers of Office are no longer updated (at least for the time being). That means that – even for Office 2019 – the value used in Registry keys and the value returned by
Application.Version
(e.g. in Word) still is16.0
.For the time being, there is no documented way to distinguish the Office 2016 from Office 2019. A clue might be the file version of the winword.exe; however, this version is also incremented for patched Office 2016 versions (see the comment by @antonio below).
If you need to distinguish somehow between Office versions, e.g. to make sure that a certain feature is present or that a minimum version of Office is installed, probably the best way it to look at the file version of one of the main Office applications:The file version of Office 2019 is 16.0.10730.20102, so if you see anything greater than that you are dealing with Office 2019 or a current Office 365 version.If you've installed 32-bit Office on a 64-bit machine, you may need to check for the presence of "SOFTWARE\Wow6432Node\Microsoft\Office\12.0\", substituting the 12.0 with the appropriate version. This is certainly the case for Office 2007 installed on 64-bit Windows 7.
Note that Office 2010 (== 14.0) is the first Office for which a 64-bit version exists.
I know the question has been asked and answered a long time ago, but this same question has kept me busy until I made this observation:
To get the build number (e.g.
15.0.4569.1506
), probeHKLM\SOFTWARE\Microsoft\Office\[VER]\Common\ProductVersion::LastProduct
, where[VER]
is the major version number (12.0 for Office 2007, 14.0 for Office 2010, 15.0 for Office 2013).On a 64-bit Windows, you need to insert
Wow6432Node
between theSOFTWARE
andMicrosoft
crumbs, irrespective of the bitness of the Office installation.On my machines, this gives the version information of the originally installed version. For Office 2010 for instance, the numbers match the ones listed here, and they differ from the version reported in
File > Help
, which reflects patches applied by hotfixes.How about HKEY_CLASSES_ROOT\Word.Application\CurVer?