Search code examples
inno-setuppascalscript

Using code (Exec function) in Inno Setup


I cannot use Exec function in my Inno Setup script.

I tried execute an example like:

var Code: Integer;
begin
  Exec('reg.exe', 'import C:\Support\*.reg', '', SW_HIDE, ewWaitUntilTerminated, Code)
end;

But no success, I have an error:

period '.' expected.

How can I execute my code (reg file)?


Solution

  • You cannot place your code like this without any context.

    You have to place the code into some event function in the [Code] section:

    For example CurStepChanged may be, what you want:

    [Code]
    
    procedure CurStepChanged(CurStep: TSetupStep);
    var
      Code: Integer;
    begin
      if CurPageID = ssInstall then
      begin
        Exec('reg.exe', 'import C:\Support\*.reg', '', SW_HIDE, ewWaitUntilTerminated, Code);
      end;
    end;