Mere moments ago, quoth I:
> The easy way is to use "net start"/"net stop" instead of SC -- SC is
> asynchronous so it will request the start/stop but not actually wait for
> it, while net will wait for it to complete before returning.
Another thing to watch out for is exactly where in your own code you're
issuing the "service status = stopped" indication.
You want to issue "service status = stopping" almost immediately, and
then clean up absolutely everything you can (including destroying
threads and global objects) and only issue the "stopped" status as the
absolute last thing before your process exits. (Global destructors will
run after this, but you want to ensure that they have already been
cleaned up so there's nothing to do.)
There will be a window of time between "stopped" and when the process
actually exits and releases the file, and you want this time to be as
short as possible. Usually you don't need to make any special effort to
ensure this as long as you've issued it as the last thing with little to
no additional subsequent cleanup -- especially if you're running "net
stop" since the time for *that* process to stop and exit should
hopefully be similar to that of the service process.
If you can't completely eliminate this as a problem, then you may need
to explicitly wait for the service process to terminate as well.
Although note that Inno's own default Restart Manager checks (which run
after PrepareToInstall) will handle some of this as well.