Search code examples
inno-setuppascalscript

How to add Sleep In Pascal Script (Inno Setup) which will execute before Extraction of Files


I'm trying to make a installer, which will uninstall the older installation before installing the new installation.

The problem I am facing is that, that the uninstaller stops and then removes the installed service, after removing service, windows takes 15 sec to remove that service, waituntilterminated flag doesn't help,

Because remove service command (I.e. service.exe remove) finishes in under 1 sec

All I want is to add a 15 sec Sleep which will execute after all the processes under [UninstallRun] finishes, or before the actual extraction of file takes place

Because, otherwise uninstaller fails to delete all the files, as the process is still running for 15 sec

Due to which, Reinstallation, throws an error that, Delete File fails Access Denied,

If I wait for 15 sec and then click on retry, then the installer is able overwrite old files


Solution

  • The most trivial solution is to make the sleep part of your uninstall command. You can use the timeout command.

    [UninstallRun]
    Filename: cmd; Parameters: "/c service.exe remove && timeout /t 15 /nobreak"; \
         Flags: runhidden
    

    Better might be to instead execute the service.exe remove from Pascal Script, from the CurUninstallStepChanged(usPostUninstall) event. Then you can use the Sleep function.


    Though even better would be to check when the service really finishes, instead of waiting an arbitrary amount of time.

    See for example How to uninstall the program when it is running and only after the user's confirmation to close and uninstall it - Inno Setup.