使用注册表检测安装的 MS Office 是 32 位还是 64 位。

5

我想安装基于Excel版本(32位或64位)的VSTO插件。 我计划打包32位和64位的MSIS,并通过确定Excel版本来安装其中之一。 我能够找到这个链接,通过使用注册表来检测2010 Office是32位还是64位。 检测Office是否为32位或64位 但我想检查Excel 2007和2013是否为32位或64位。 是否通过注册表可以检测它们。

4个回答

7

首先,在以下注册表键中查找安装的Outlook版本:

HKEY_CLASSES_ROOT\Outlook.Application\CurVer

该值将为Outlook.Application.15(适用于2013)。然后解析该值以获取整数,并查找以下注册表键:

HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Office\15.0\Outlook

如果存在,请检查Bitness的值以确定它是32位(x86)还是64位(x64)。如果不存在,则假定为32位。


3

给定:Office32安装在“Program Files(x86)”中,这对我来说有效。

我基本上检查winword.exe是否在该键的下面某个地方。如果他们没有安装Word部分,那么现在很难处理。我使用这个可变地运行32位或64位的msi安装程序来安装office。

<Fragment>
<Property Id="IS_32BITOFFICE">
  <DirectorySearch Path="[ProgramFilesFolder]\Microsoft Office"                  
                   Depth="4"                   
                   AssignToProperty="no"                   
                   Id="IS_32BIT_OFFICE_DIRSEARCH">
    <FileSearch   Name="winword.exe" />
  </DirectorySearch>
</Property>

<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
  <Component Id="WIN64_OFFICE32_MSI">
    <File Id="WIN64_OFFICE32_MSI" src="WIN64_OFFICE32.txt"/>
    <Condition>IS_32BITOFFICE</Condition>
  </Component> 
  <Component Id="WIN64_OFFICE64_MSI">
    <File Id="WIN64_OFFICE64_MSI" src="WIN64_OFFICE64.txt"/>
    <Condition>NOT IS_32BITOFFICE</Condition>
  </Component> 
    </ComponentGroup>
</Fragment>

3

你不能可靠地从注册表(直接调用)中检测它。更好的方法是在C#或VB.net中创建自定义安装程序模块,获取应用程序的ProductCode。从产品代码中,你可以得到Bitness。

产品代码也是从注册表中获取的,但让Office应用程序处理它。

Private IsExcel32Bit As Boolean = False
Private IsExcel64Bit As Boolean = False
Private ReadOnly STR_prdCodeDelimeter As Char = CChar("-")

Private Sub GetExcelBitness(ByVal exApp As Microsoft.Office.Interop.Excel.Application)
    Dim prdCode As String = exApp.ProductCode
    If Not String.IsNullOrEmpty(prdCode) AndAlso CInt(prdCode.Split(STR_prdCodeDelimeter)(3)(0).ToString) = 0 Then
        IsExcel32Bit = True
    ElseIf Not String.IsNullOrEmpty(prdCode) AndAlso CInt(prdCode.Split(STR_prdCodeDelimeter)(3)(0).ToString) = 1 Then
        IsExcel64Bit = True
    End If
End Sub

顺便说一下,将安装程序分开保存将有助于您未来的使用。如果未正确安装Microsoft Office,则产品代码有时可能为空或错误。


2

我想找到 Office 2013 应用程序的位数。 - siva
同样的方法也适用于Office 2013。 - Eugene Astafiev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接