Getting the version and platform of Office application from Windows Registry
Asked Answered
T

2

2

I'm working on a Inno Setup installer for an MS Office Add-In and trying to find a way to get the version and target platform (bitness) of Excel and Outlook, preferably from the Windows Registry. Although some unofficial sources list some methods to extract version information from the Windows Registry, that information appears to be unreliable.

Does anyone know if there is a reliable (and official) way to get version and platform information from the version of Office (and associated programs such Excel or Outlook) that is currently installed?

Typeset answered 22/11, 2017 at 9:29 Comment(0)
V
2

Based on the answers by @Slava Ivanov and @MB., a code for Inno Setup is:

const
  AppPathsKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths';

const
  SCS_32BIT_BINARY = 0;
  SCS_64BIT_BINARY = 6;

function GetBinaryType(ApplicationName: string; var BinaryType: Integer): Boolean;
  external '[email protected] stdcall';

function GetAppVersionAndBinaryType(
  ProgramFileName: string; var Version: string; var BinaryType: Integer): Boolean;
var
  ProgramPath: string;
begin
  Result :=
    RegQueryStringValue(HKLM, AppPathsKey + '\' + ProgramFileName, '', ProgramPath);
  if not Result then
  begin
    Log(Format('Cannot find a path to "%s"', [ProgramFileName]));
  end
    else
  begin
    Log(Format('Path to "%s" is "%s"', [ProgramFileName, ProgramPath]));
    Result := GetVersionNumbersString(ProgramPath, Version);
    if not Result then
    begin
      Log(Format('Cannot retrieve a version of "%s"', [ProgramFileName]));
    end
      else
    begin
      Log(Format('Version of "%s" is "%s"', [ProgramFileName, Version]));

      Result := GetBinaryType(ProgramPath, BinaryType);
      if not Result then
      begin
        Log(Format('Cannot retrieve a binary type of "%s"', [ProgramFileName]));
      end
        else
      begin
        Log(Format('Binary type of "%s" is "%d"', [ProgramFileName, BinaryType]));
      end;
    end;
  end;
end;

The code is for Unicode version of Inno Setup.

Volkan answered 22/11, 2017 at 20:49 Comment(0)
G
1

The following are the steps to get the information ...

  • Use HKEY_LOCAL_MACHINE root and query the path of the application from the keys below ...

    Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE
    Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe
    

    When query those keys (Default) value you will get the path to the actual file on the filesystem, for example:

    C:\Program Files\Microsoft Office\Root\Office16\OUTLOOK.EXE
    

    Please note you need to query according to the OS bitness with KEY_WOW64_64KEY or KEY_WOW64_32KEY flag.

  • Use this path to an application and retrieve actual file property "Product version" for example 16.0.8625.2121. Parse it to get major, minor and build numbers.

  • Once again use HKEY_LOCAL_MACHINE with KEY_WOW64_64KEY or KEY_WOW64_32KEY flag to query the Bitness key ...

    Software\Microsoft\Office\%d.0\Outlook
    

    Where %d is the major version of the product. If returned value equal x64 Outlook 64 bit version installed.

EDIT:

There are few more solutions (even some spacial for Inno Setup) can be found at Detect whether Office is 32bit or 64bit via the registry thread. Please check it out.

Grandiose answered 22/11, 2017 at 17:30 Comment(5)
Does the last point work for Excel too? I have Excel 2016 32-bit and I do not have any Software\Microsoft\Office\%d.0\Excel key (I do not have Outlook installed to check).Volkan
@MartinPrikryl The key Bitness is available for Outlook. I believe this key is important as any add-in has to use appropriate MAPI. For other Office applications people use ::GetBinaryType function. You may read more about Excel bitness identification: Detect whether Office is 32bit or 64bit via the registryGrandiose
OK, so using GetBinaryType seems to be a better approach. Maybe you should edit this into your answer, including the link to the other question. +1 (while ago already) - I've posted my own answer with a code based on your answer.Volkan
@MartinPrikryl The question was about "reliable" way. I described the way we are using for years and it works solid well. Please note, I am Outlook guy, so couldn't comment much on Excel, but Bitness value can be used for other products as it will exists even if Outlook was not installed. I'll update my answer with link to SO thread, as you suggested, but won't bring anything into my answer from this thread. I appreciated your tip. Ye, and your solution may be more suitable for someone who uses Inno Setup (+1) as copy and it works.Grandiose
Well, as I wrote, I do not have Software\Microsoft\Office\%d.0\Outlook, despite having Office (but not Outlook) installed (neither in WOW6432Node nor in the 64-bit key)Volkan

© 2022 - 2024 — McMap. All rights reserved.