Detect whether Office is 32bit or 64bit via the registry

前端 未结 28 1151
春和景丽
春和景丽 2020-11-29 21:29

Now that Office also comes in a 64bit install, where in the registry do you find out if the version of Office installed is 32bit or 64bit?

28条回答
  •  悲哀的现实
    2020-11-29 22:16

    To add to vtrz's answer, here's a function I wrote for Inno Setup:

    const
      { Constants for GetBinaryType return values. }
      SCS_32BIT_BINARY = 0;
      SCS_64BIT_BINARY = 6;
      { There are other values that GetBinaryType can return, but we're }
      { not interested in them. }
    
    { Declare Win32 function  }
    function GetBinaryType(lpApplicationName: AnsiString; var lpBinaryType: Integer): Boolean;
    external 'GetBinaryTypeA@kernel32.dll stdcall';
    
    function Is64BitExcelFromRegisteredExe(): Boolean;
    var
      excelPath: String;
      binaryType: Integer;
    begin
      Result := False; { Default value - assume 32-bit unless proven otherwise. }
      { RegQueryStringValue second param is '' to get the (default) value for the key }
      { with no sub-key name, as described at }
      { http://stackoverflow.com/questions/913938/ }
      if IsWin64() and RegQueryStringValue(HKEY_LOCAL_MACHINE,
          'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe',
          '', excelPath) then begin
        { We've got the path to Excel. }
        try
          if GetBinaryType(excelPath, binaryType) then begin
            Result := (binaryType = SCS_64BIT_BINARY);
          end;
        except
          { Ignore - better just to assume it's 32-bit than to let the installation }
          { fail.  This could fail because the GetBinaryType function is not }
          { available.  I understand it's only available in Windows 2000 }
          { Professional onwards. }
        end;
      end;
    end;
    

提交回复
热议问题