我如何以编程方式找到正确的Microsoft Office产品版本号(服务包)? [英] How can I programmatically find the correct Microsoft Office product version number (and service pack)?

查看:321
本文介绍了我如何以编程方式找到正确的Microsoft Office产品版本号(服务包)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦找几Office产品一致的版本号。

I'm having trouble finding a consistent version number for several Office products.

这<一href="http://stackoverflow.com/questions/2514511/how-can-i-determine-if-ms-office-2007-sp2-is-installed">post使我这表明不同的方式来寻找服务包 Office 2007的以及这些知识库文章<一个HREF =htt​​p://support.microsoft.com/kb/2121559相对=nofollow>的Office 2010 产品。

This post led me to these KB articles which suggest different ways to find the service packs for Office 2007 and Office 2010 products.

不过,该办公室的文件版本的.exe文件与图表相一致。

However, the file versions of the Office .exe files are not consistent with the chart.

使用,例如,安装在我的机器上的Excel 2010中:

Using the Excel 2010 installed on my machine as an example:

  • 帮助>关于Excel的信息:微软的Excel 2010(14.0.6106.5005)SP1
  • 在文件版本通过查看Excel.exe中的属性:14.0.6106.5005
  • 在原始文件版本(从表):14.0.4756.1000
  • 在SP1文件版本(从表):14.0.6024.1000

有没有更可靠的方式来获取版本号和Service Pack的Microsoft Office产品?

Is there a more reliable way to retrieve version numbers and service packs for Microsoft Office products?

推荐答案

我们决定支持这个,因为它采取了太多的时间。不过,我想我会后我得到了什么,以防有人需要把它更远。

We decided to back out of this because it was taking way too much time. However, I thought I'd post what I got in case anyone needs to take it farther.

首先,这里有三个相关的知识库文章,其中列出了服务包的版本:

First, here are the three relevant KB articles which list out the service pack versions:

  • Office 2003
  • Office 2007
  • Office 2010

2的方法在这些文章中提出的可执行文件的属性,是一种可靠的方式来获得实际的文件版本。不幸的是,事实并非如此。

Method 2 in these articles suggest the properties of the executable file is a reliable way to get the actual file version. Unfortunately, it isn't.

这里是你如何能找到可执行

查找安装根处:

// version is one of these three: Office 2003 = 11, Office 2007 = 12, Office 2010 = 14
RegistryKey registryKey = 
    Registry.LocalMachine.OpenSubKey(String.Format(
        @"SOFTWARE\Microsoft\Office\{0}.0\Common\InstallRoot", (int)version));

if (registryKey == null)
    registryKey = Registry.LocalMachine.OpenSubKey(
        registryKeyPath.Insert("SOFTWARE".Length, "\\Wow6432Node"));

if (registryKey != null)
    installRoot = registryKey.GetValue("Path").ToString();

然后附加可执行文件的名称(与例外的Office 2003):

Then append the name of the executable (with on exception for Office 2003):

  • 访问:MSACCESS.EXE
  • 在Excel中:EXCEL.EXE
  • 展望:OUTLOOK.EXE(使用OUTLIB.DLL 2003年)
  • 在PowerPoint中:POWERPNT.EXE
  • 字:WINWORD.EXE

通过这些信息,您可以获得FileVersionInfo所选应用程序。使用Word为例:

With this information, you can get the FileVersionInfo for the selected application. Using Word as an example:

FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(
    Path.Combine(installRoot, "WINWORD.EXE"));

if (fileVersionInfo != null)
    fileVersion = fileVersionInfo.FileVersion;

从理论上讲,你现在可以比较这版本号从知识库文章的表中查找正确的Service Pack。这是我放弃了我的努力在问题中列出的原因 - 你会发现版本号就是不匹配。

Theoretically, you could now compare this version number to the tables from the KB articles to find the correct service pack. This is where I abandoned my efforts for the reasons listed in the question - you'll find the version numbers just don't match up.

您可以用code类似于下面的比较版本作为,说的Word 2010 SP1:

You can use code similar to below to compare the versions for, say Word 2010 SP1:

Version version = new Version(fileVersion);
if (version >= new Version("14.0.6024.1000"))
    servicePack = 1

下面是一些code为获得Office套件的版本

Here's some code to get the version of Office suite:

string msodllPath = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
    String.Format(@"Common Files\microsoft shared\OFFICE{0}\MSO.DLL", (int)Version));

if (!File.Exists(msodllPath))
    msodllPath = msodllPath.Replace("Program Files", "Program Files (x86)");

if (File.Exists(msodllPath))
{
    FileVersionInfo msodll = FileVersionInfo.GetVersionInfo(msodllPath);
    FileVersion = new Version(msodll.FileVersion);
}

如果您正试图获取版本名称(即专业版,旗舰版,学生等),你是在冒险。下面是一些的未经测试的code片段,可能是有用的。这是为每个版本的办公室和每个版本等等好运!不同的

If you are trying to get the edition name (i.e. Professional, Ultimate, Student, etc) you are in for an adventure. Here's some untested code fragments that may be useful. It's different for each version of office and each edition so best of luck!

string fullNameRegistryKey = "";

if (Version == OfficeVersion.Office2010)
    fullNameRegistryKey = String.Format(
        @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office{0}.PROPLUSR",
        (int)Version);
else if (Version == OfficeVersion.Office2007)
    fullNameRegistryKey = String.Format(
        @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PRO",
       (int)Version);

RegistryKey installRootRegistryKey = GetSoftwareRegistryKey(fullNameRegistryKey);

if (installRootRegistryKey != null)
    FullName = installRootRegistryKey.GetValue("DisplayName")
        .ToString().Replace("Microsoft ", "");

这篇关于我如何以编程方式找到正确的Microsoft Office产品版本号(服务包)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆