首页 > 解决方案 > 使用 Inno Setup 安装 mod/plugin 时如何从注册表中获取目标游戏/应用程序的安装路径?

问题描述

我想为游戏的mod创建安装程序。我需要检测安装游戏的位置。我知道注册表中游戏的路径在哪里。但是游戏可以在另一个启动器中——Steam、GOG。如何按顺序检测?

例如:

注册表项:

我知道如何检测一条路径

DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 475150, InstallLocation}

但我不知道如何检测到多少条路径。

标签: registryinstallationinno-setuppascalscript

解决方案


使用脚本常量RegQueryStringValue函数

[Setup]
DefaultDirName={code:GetInstallationPath}

[Code]
var
  InstallationPath: string;

function GetInstallationPath(Param: string): string;
begin
  { Detected path is cached, as this gets called multiple times }
  if InstallationPath = '' then
  begin
    if RegQueryStringValue(
         HKLM64, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 475150',
         'InstallLocation', InstallationPath) then
    begin
      Log('Detected Steam installation: ' + InstallationPath);
    end
      else
    if RegQueryStringValue(
         HKLM32, 'SOFTWARE\GOG.com\Games\1196955511',
         'path', InstallationPath) then
    begin
      Log('Detected GOG installation: ' + InstallationPath);
    end
      else
    begin
      InstallationPath := 'C:\your\default\path';
      Log('No installation detected, using the default path: ' + InstallationPath);
    end;
  end;
  Result := InstallationPath;
end;

推荐阅读