Detect whether MS Office installed is 32bit or 64bit by using registry

前端 未结 4 1773
Happy的楠姐
Happy的楠姐 2021-01-14 06:01

I want to install vsto addin based on the excel version (32 bit or 64 bit). I am planning to bundle both 32bit and 64 bit msis and install one by determining the excel versi

4条回答
  •  抹茶落季
    2021-01-14 06:15

    You can't reliably detect it from registry (direct call). Better is to create Custom installer module in C# or VB.net, fetch ProductCode of application. From product code, you can get the Bitness.

    Product code is also fetched from registry, but let Office application handle it.

    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
    

    Btw keeping both installer separately is going to help you in future. Sometimes product code might be null or wrong if MS Office is not installed properly.

提交回复
热议问题