Search code examples
inno-setuppascalscript

Using function return value in Inno Setup [Registry]


Is there anyway to have the return value of a function for the ValueData (or similar property). Tried the following:

Root: HKLM; \
   Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
   ValueType: string; ValueName: "Hostname"; ValueData: GetComputerNameString(); \
   Flags: preservestringtype;

But this simply adds the string GetComputerNameString() to the registry item.


Solution

  • Use a scripted constant, with syntax {code:FunctionName}. Though the scripted constant function must take a string parameter (even if the actual implementation does not need any parameter). So the GetComputerNameString is not compatible. You have to create a proxy function.

    [Registry]
    Root: HKLM; \
        Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
        ValueType: string; ValueName: "Hostname"; ValueData: {code:GetComputerName}; \
        Flags: preservestringtype;
    
    [Code]
    
    function GetComputerName(Param: string): string;
    begin
      Result := GetComputerNameString;
    end; 
    

    For a more complex example, see Inno Setup [Code] section variable to [Registry].