我正在为 MS Office 插件开发 Inno Setup 安装程序,并试图找到一种方法来获取 Excel 和 Outlook 的版本和目标平台(位数),最好从 Windows 注册表中获取。 尽管一些非官方来源列出了一些从 Windows 注册表中提取版本信息的方法,但该信息似乎不可靠。
有谁知道是否有可靠的(官方)方法从当前安装的 Office(以及 Excel 或 Outlook 等相关程序)版本获取版本和平台信息?
根据 @Slava Ivanov 和 @MB. 的回答,Inno Setup 的代码是:
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;
该代码适用于 Inno Setup 的 Unicode 版本。
以下是获取信息的步骤...
使用
HKEY_LOCAL_MACHINE
root 并通过以下按键查询应用程序的路径...
Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE
Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe
当查询这些键
(Default)
值时,您将获得文件系统上实际文件的路径,例如:
C:\Program Files\Microsoft Office\Root\Office16\OUTLOOK.EXE
请注意,您需要根据操作系统位数使用
KEY_WOW64_64KEY
或 KEY_WOW64_32KEY
标志进行查询。使用此应用程序路径并检索实际文件属性“产品版本”,例如
16.0.8625.2121
。解析它以获得主要、次要和内部版本号。再次使用
HKEY_LOCAL_MACHINE
和 KEY_WOW64_64KEY
或 KEY_WOW64_32KEY
标志来查询 Bitness
键...
Software\Microsoft\Office\%d.0\Outlook
其中
%d
是产品的主要版本。如果返回值等于 x64
Outlook 64 位版本已安装。编辑:
还有一些更多的解决方案(甚至是 Inno Setup 的一些特殊解决方案)可以在 通过注册表检测 Office 是 32 位还是 64 位线程中找到。请检查一下。