Inno Setup - Setting DefaultDir using wildcard registry entry?

前端 未结 2 1251
礼貌的吻别
礼貌的吻别 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;
    

提交回复
热议问题