Eugene Chefranov
Eugene Chefranov

Reputation: 171

How to get path of installation of target game/application from registry when installing mod/plugin using Inno Setup?

I would like to create installer for mod of the game. And I need to detect where is installed the game. I know where is path of the game in registry. But the game can be in another launchers - Steam, GOG. How to detect in order?

For example:

Registry keys:

I know how detect one path

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

But I don't know how detect many paths.

Upvotes: 3

Views: 2995

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202642

Use a scripted constant and RegQueryStringValue function:

[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;

Upvotes: 5

Related Questions