如何检测MS-Office的已安装版本?

时间:2021-03-29 07:00:44

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.

有人知道什么是检测安装了哪个版本的Office的最好方法吗?另外,如果安装了多个版本的Office,我想知道它们是什么版本。如果我能够检测到已安装的Excel的特定版本,则会有额外的好处。

8 个解决方案

#1


62  

One way to check for the installed Office version would be to check the InstallRoot registry keys for the Office applications of interest.

检查已安装的Office版本的一种方法是检查有关Office应用程序的InstallRoot注册表项。

For example, if you would like to check whether Word 2007 is installed you should check for the presence of the following Registry key:

例如,如果您想检查Word 2007是否安装了,您应该检查以下注册表项的存在:

HKLM\Software\Microsoft\Office\12.0\Word\InstallRoot::Path

This entry contains the path to the executable.

该条目包含可执行文件的路径。

Replace 12.0 (for Office 2007) with the corresponding version number:

用相应的版本号替换12.0 (Office 2007):

Office 97   -  7.0
Office 98   -  8.0
Office 2000 -  9.0
Office XP   - 10.0
Office 2003 - 11.0
Office 2007 - 12.0
Office 2010 - 14.0 (sic!)
Office 2013 - 15.0
Office 2016 - 16.0

The other applications have similar keys:

其他应用程序有类似的键:

HKLM\Software\Microsoft\Office\12.0\Excel\InstallRoot::Path
HKLM\Software\Microsoft\Office\12.0\PowerPoint\InstallRoot::Path

Or you can check the common root path of all applications:

或查看所有应用程序的共同根路径:

HKLM\Software\Microsoft\Office\12.0\Common\InstallRoot::Path

Another option, without using specific Registry keys would be to query the MSI database using the MSIEnumProducts API as described here.

另一个不使用特定注册表键的选项是使用这里描述的MSIEnumProducts API查询MSI数据库。

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.

顺便说一句,不同Office版本的并行安装没有得到微软的官方支持。它们做了一些工作,但是您可能会得到不希望的效果和不一致。

#2


21  

How about HKEY_CLASSES_ROOT\Word.Application\CurVer?

HKEY_CLASSES_ROOT \ Word.Application \曲线呢?

#3


13  

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.

如果您已经在64位机器上安装了32位的Office,您可能需要检查是否有“SOFTWARE\Wow6432Node\Microsoft\Office\12.0\”,将12.0替换为适当的版本。这当然是安装在64位Windows 7上的Office 2007的情况。

Note that Office 2010 (== 14.0) is the first Office for which a 64-bit version exists.

注意,Office 2010(== 14.0)是第一个存在64位版本的Office。

#4


9  

I found this CodeProject which helped me out with this very problem: http://www.codeproject.com/Articles/26520/Getting-Office-s-Version

我找到了这个帮助我解决这个问题的代码项目:http://www.codeproject.com/Articles/26520/Getting-Office-s-Version

#5


7  

namespace Software_Info_v1._0
{
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop;

public class MS_Office
{
    public string GetOfficeVersion()
    {
        string sVersion = string.Empty;
        Microsoft.Office.Interop.Word.Application appVersion = new Microsoft.Office.Interop.Word.Application();
        appVersion.Visible = false;
        switch (appVersion.Version.ToString())
        {
            case "7.0":
                sVersion = "95";
                break;
            case "8.0":
                sVersion = "97";
                break;
            case "9.0":
                sVersion = "2000";
                break;
            case "10.0":
                sVersion = "2002";
                break;
            case "11.0":
                sVersion = "2003";
                break;
            case "12.0":
                sVersion = "2007";
                break;
            case "14.0":
                sVersion = "2010";
                break;
            default:
                sVersion = "Too Old!";
                break;
        }
        Console.WriteLine("MS office version: " + sVersion);
        return null;
    }



}
}

#6


5  

Why not check HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\[office.exe], where [office.exe] stands for particular office product exe-filename, e.g. winword.exe, excel.exe etc. There you get path to executable and check version of that file.

为什么不试试HKLM\软件?exe],[办公室。代表特定的office产品的exe-filename,例如winword。exe,excel。exe等。在那里你可以找到可执行文件的路径,并检查该文件的版本。

How to check version of the file: in C++ / in C#

如何检查文件的版本:在c++ / c#中?

Any criticism towards such approach?

对这种做法有什么批评吗?

#7


2  

A bonus would be if I can detect the specific version(s) of Excel that is(/are) installed.

如果我能够检测到已安装的Excel的特定版本,则会有额外的好处。

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), probe HKLM\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).

为获得建造编号(例如15.0.4569.1506),调查HKLM\软件\微软\ \ \ \ \ \ \ \ \ \ \ \ - \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

On a 64-bit Windows, you need to insert Wow6432Node between the SOFTWARE and Microsoft crumbs, irrespective of the bitness of the Office installation.

在64位的Windows上,您需要在软件和微软的面包屑之间插入wow6432节点,而不考虑办公室安装的bitness。

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.

在我的机器上,这提供了最初安装版本的版本信息。例如,在Office 2010中,这些数字与这里列出的数字相匹配,它们与在>帮助下报告的版本不同,后者反映了热修复程序所应用的补丁。

#8


-1  

        public string WinWordVersion
        {
            get
            {
                string _version = string.Empty;
                Word.Application WinWord = new Word.Application();   

                switch (WinWord.Version.ToString())
                {
                    case "7.0":  _version = "95";
                        break;
                    case "8.0": _version = "97";
                        break;
                    case "9.0": _version = "2000";
                        break;
                    case "10.0": _version = "2002";
                        break;
                    case "11.0":  _version = "2003";
                        break;
                    case "12.0": _version = "2007";
                        break;
                    case "14.0": _version = "2010";
                        break;
                    case "15.0":  _version = "2013";
                        break;
                    case "16.0": _version = "2016";
                        break;
                    default:                            
                        break;
                }

                return WinWord.Caption + " " + _version;
            }
        }

#1


62  

One way to check for the installed Office version would be to check the InstallRoot registry keys for the Office applications of interest.

检查已安装的Office版本的一种方法是检查有关Office应用程序的InstallRoot注册表项。

For example, if you would like to check whether Word 2007 is installed you should check for the presence of the following Registry key:

例如,如果您想检查Word 2007是否安装了,您应该检查以下注册表项的存在:

HKLM\Software\Microsoft\Office\12.0\Word\InstallRoot::Path

This entry contains the path to the executable.

该条目包含可执行文件的路径。

Replace 12.0 (for Office 2007) with the corresponding version number:

用相应的版本号替换12.0 (Office 2007):

Office 97   -  7.0
Office 98   -  8.0
Office 2000 -  9.0
Office XP   - 10.0
Office 2003 - 11.0
Office 2007 - 12.0
Office 2010 - 14.0 (sic!)
Office 2013 - 15.0
Office 2016 - 16.0

The other applications have similar keys:

其他应用程序有类似的键:

HKLM\Software\Microsoft\Office\12.0\Excel\InstallRoot::Path
HKLM\Software\Microsoft\Office\12.0\PowerPoint\InstallRoot::Path

Or you can check the common root path of all applications:

或查看所有应用程序的共同根路径:

HKLM\Software\Microsoft\Office\12.0\Common\InstallRoot::Path

Another option, without using specific Registry keys would be to query the MSI database using the MSIEnumProducts API as described here.

另一个不使用特定注册表键的选项是使用这里描述的MSIEnumProducts API查询MSI数据库。

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.

顺便说一句,不同Office版本的并行安装没有得到微软的官方支持。它们做了一些工作,但是您可能会得到不希望的效果和不一致。

#2


21  

How about HKEY_CLASSES_ROOT\Word.Application\CurVer?

HKEY_CLASSES_ROOT \ Word.Application \曲线呢?

#3


13  

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.

如果您已经在64位机器上安装了32位的Office,您可能需要检查是否有“SOFTWARE\Wow6432Node\Microsoft\Office\12.0\”,将12.0替换为适当的版本。这当然是安装在64位Windows 7上的Office 2007的情况。

Note that Office 2010 (== 14.0) is the first Office for which a 64-bit version exists.

注意,Office 2010(== 14.0)是第一个存在64位版本的Office。

#4


9  

I found this CodeProject which helped me out with this very problem: http://www.codeproject.com/Articles/26520/Getting-Office-s-Version

我找到了这个帮助我解决这个问题的代码项目:http://www.codeproject.com/Articles/26520/Getting-Office-s-Version

#5


7  

namespace Software_Info_v1._0
{
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop;

public class MS_Office
{
    public string GetOfficeVersion()
    {
        string sVersion = string.Empty;
        Microsoft.Office.Interop.Word.Application appVersion = new Microsoft.Office.Interop.Word.Application();
        appVersion.Visible = false;
        switch (appVersion.Version.ToString())
        {
            case "7.0":
                sVersion = "95";
                break;
            case "8.0":
                sVersion = "97";
                break;
            case "9.0":
                sVersion = "2000";
                break;
            case "10.0":
                sVersion = "2002";
                break;
            case "11.0":
                sVersion = "2003";
                break;
            case "12.0":
                sVersion = "2007";
                break;
            case "14.0":
                sVersion = "2010";
                break;
            default:
                sVersion = "Too Old!";
                break;
        }
        Console.WriteLine("MS office version: " + sVersion);
        return null;
    }



}
}

#6


5  

Why not check HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\[office.exe], where [office.exe] stands for particular office product exe-filename, e.g. winword.exe, excel.exe etc. There you get path to executable and check version of that file.

为什么不试试HKLM\软件?exe],[办公室。代表特定的office产品的exe-filename,例如winword。exe,excel。exe等。在那里你可以找到可执行文件的路径,并检查该文件的版本。

How to check version of the file: in C++ / in C#

如何检查文件的版本:在c++ / c#中?

Any criticism towards such approach?

对这种做法有什么批评吗?

#7


2  

A bonus would be if I can detect the specific version(s) of Excel that is(/are) installed.

如果我能够检测到已安装的Excel的特定版本,则会有额外的好处。

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), probe HKLM\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).

为获得建造编号(例如15.0.4569.1506),调查HKLM\软件\微软\ \ \ \ \ \ \ \ \ \ \ \ - \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

On a 64-bit Windows, you need to insert Wow6432Node between the SOFTWARE and Microsoft crumbs, irrespective of the bitness of the Office installation.

在64位的Windows上,您需要在软件和微软的面包屑之间插入wow6432节点,而不考虑办公室安装的bitness。

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.

在我的机器上,这提供了最初安装版本的版本信息。例如,在Office 2010中,这些数字与这里列出的数字相匹配,它们与在>帮助下报告的版本不同,后者反映了热修复程序所应用的补丁。

#8


-1  

        public string WinWordVersion
        {
            get
            {
                string _version = string.Empty;
                Word.Application WinWord = new Word.Application();   

                switch (WinWord.Version.ToString())
                {
                    case "7.0":  _version = "95";
                        break;
                    case "8.0": _version = "97";
                        break;
                    case "9.0": _version = "2000";
                        break;
                    case "10.0": _version = "2002";
                        break;
                    case "11.0":  _version = "2003";
                        break;
                    case "12.0": _version = "2007";
                        break;
                    case "14.0": _version = "2010";
                        break;
                    case "15.0":  _version = "2013";
                        break;
                    case "16.0": _version = "2016";
                        break;
                    default:                            
                        break;
                }

                return WinWord.Caption + " " + _version;
            }
        }