title: Call Function From Procedure in Inno Setup?
body: <p>I'm trying to check if a service that I just installed is running or not before exit in Inno Setup. I need to execute a program just after so I am trying to call a procedure that uses a function from BeforeInstall in a run parameter. </p>
  
  <p>I found this example from another post and I'm trying to alter it to check if my service is running after it installs but before the run line is executed. I'm new to pascal and I can't seem to work out how to call the function from the procedure. Any help would be appreciated. Thanks!</p>
  
  <pre><code>[Run]
  ; Launch the Setup App here
  Filename: "{app}\MyApp.exe"; BeforeInstall: AfterInstallProc
  
  [Code]
  procedure AfterInstallProc;
  begin
    result := not IsAppRunning('MyService.exe');
    if not result then
      MsgBox('Error message here', mbError, MB_OK);
  end;
  
  function IsAppRunning(const FileName : string): Boolean;
  var
    FSWbemLocator: Variant;
    FWMIService : Variant;
    FWbemObjectSet: Variant;
  begin
    Result := false;
    FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');
    FWMIService := FSWbemLocator.ConnectServer('', 'root\CIMV2', '', '');
    FWbemObjectSet := FWMIService.ExecQuery(Format('SELECT Name FROM Win32_Process Where Name="%s"',[FileName]));
    Result := (FWbemObjectSet.Count &gt; 0);
    FWbemObjectSet := Unassigned;
    FWMIService := Unassigned;
    FSWbemLocator := Unassigned;
  end;
  </code></pre>