PrepareToInstall timing
<p>I'm using the PrepareToInstall event to stop and remove a service.
This works fine, no errors are thrown.</p>

<p>However SOMETIMES there seems to be a timing problem because SOMETIMES InnoSetup tells me that 'oscmaintenanceservice' is still running and asks whether it should close it.</p>

<p>I thought that if the API returns from the function to close and remove the service, the app should already be gone.</p>

<p>Does anybody see any mistake on my side or has any suggestions for me?</p>

<p>Thank you!</p>

<pre><code>function PrepareToInstall(var NeedsRestart: Boolean): String;
begin

    //MsgBox('ssInstall.', mbInformation, MB_OK);

   if IsServiceInstalled('oscmaintenanceservice') then
   BEGIN
       //MsgBox('ssInstall: Service is installed.', mbInformation, MB_OK);

       if IsServiceRunning('oscmaintenanceservice') then
           BEGIN
               //MsgBox('ssInstall: Service is running.', mbInformation, MB_OK);

               if not StopService('oscmaintenanceservice') then
               BEGIN
                   MsgBox('ssInstall: Couldnt stop service.', mbInformation, MB_OK);
               END
           else
           BEGIN
               //MsgBox('ssInstall: Service was stopped.', mbInformation, MB_OK);
           END;
       END
           else
           BEGIN
               MsgBox('ssInstall: Service not running.', mbInformation, MB_OK);
           END;
       if not RemoveService('oscmaintenanceservice') then
           BEGIN
               MsgBox('ssInstall: Couldnt remove service.', mbInformation, MB_OK);
           END
           else
           BEGIN
               //MsgBox('ssInstall: Service was removed', mbInformation, MB_OK);
           END;
   END
   else
   BEGIN
       MsgBox('ssInstall: Service not installed.', mbInformation, MB_OK);
   END;
END;
</code></pre>