Inno Setup - Setting DefaultDir using wildcard registry entry?

前端 未结 2 1252
礼貌的吻别
礼貌的吻别 2021-01-20 00:02

I\'ve recently started using Inno Setup to try and create a simple .exe installer for a game modification.

I\'ve got the installer working fine for the most part, bu

相关标签:
2条回答
  • 2021-01-20 00:34

    You can assign value of a DefaultDirName directive through the [Code] section. For instance, the following pseudo-script shows how to query two string values in registry and return the first found to the DefaultDirName directive. If none of the queried registry values is found, a default constant value is returned:

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={code:GetDirName}
    
    [Code]
    function GetDirName(Value: string): string;
    var          
      InstallPath: string;
    begin
      // initialize default path, which will be returned when the following registry
      // key queries fail due to missing keys or for some different reason
      Result := '{pf}\Default Dir Name';
      // query the first registry value; if this succeeds, return the obtained value
      if RegQueryStringValue(HKLM, 'Software\Vendor\Application', 'First Key', InstallPath) then
        Result := InstallPath
      // otherwise the first registry key query failed, so...
      else
      // query the second registry value; if it succeeds, return the obtained value
      if RegQueryStringValue(HKLM, 'Software\Vendor\Application', 'Second Key', InstallPath) then
        Result := InstallPath;
    end;
    
    0 讨论(0)
  • 2021-01-20 00:55

    In addition to using [Code] as answered elsewhere, you can also nest registry constants:

    DefaultDirName={reg:HKLM,Software\Vendor1\Application,InstallPath|{reg:HKLM,Software\Vendor2\Application,InstallPath|{pf}\DefaultInstallPath}}
    

    This will use Vendor1's path if it exists; failing that it will try Vendor2's path, and only if it cannot find either of those will it fall back to some default value.

    0 讨论(0)
提交回复
热议问题