Search code examples
inno-setup

Inno Setup: How to read the value of checkbox in postinstall


I have added a checkbox in postinstall:

[Run]
Filename: {sys}\sc.exe; Description: "This is checkbox"; Flags: postinstall shellexec runasoriginaluser unchecked

enter image description here

I want to trigger a function when clicking the button Finish if the checkbox is checked. How can I check the value?


Solution

  • What I actually needed to do was the following:

    [Run]
    Filename: "{code:MyFunction}"; Description: "This is a checkbox"; Flags: skipifdoesntexist postinstall skipifsilent
    
    [Code]
    function MyFunction(Param: String): String;
    var
        ResultCode: Integer;
    begin
        //My code
        Result := '';
    end;
    

    This will trigger MyFunction after pressing Finish only if checkbox is checked. The flag skipifdoesntexist is important here. It prevents error when the required exe file doesn't exist.