Update: Delete directory after stopping service, but before copy

79 views
Skip to first unread message

Sebastian P.R. Gingter

unread,
Apr 30, 2021, 2:34:19 AM4/30/21
to innosetup
Hello,

I seem to have some sort of a ordering problem.
My installer has components that are windows services.

The update instruction say:
Stop the service, delete all files, copy over new version, start service, done.

My problem: I can't figure out how to do that in this order, without a lot of very ugly custom code. The service creates some files in some other directories which aren't installed, so the installer doesn't know them, still I have to delete them on update.

[InstallDelete] seems too early, as the Windows Service is still running at this point. I can't delete files that are still being accessed.

BeforeInstall seems too late as we're already copying the files here, and I can't make sure I only delete the things on the first file except for a global variable... Don't really like that approach.

I could configure a DummyFile before my Directory with a BeforeInstall (for the same component) that would use the file system API to enumerate through all directories I also have listed in [Source] (I don't know how to access these, so I would need to duplicate that information, which I don't really like), to delete these, before I start processing the File entries for the actual service.

I also thought about using PrepareToInstall, but I don't know how to figure out if my component is checked (or: was checked at the initial installation run), as I have multiple services in my installer as separate components and I only should touch the services that my installer is actually processing (maybe one service was installed manually, then I should not stop that).

Did I miss something?

Thanks a lot,

  Sebastian

Sebastian P.R. Gingter

unread,
Apr 30, 2021, 6:44:42 AM4/30/21
to innosetup
Hi,

I obviously missed something:
Seems I can query WizardIsComponentSelected('myComponentName') and this tells me if that component is available.
I am currently testing if this indeed solves my problem. I am trying to check for each selected component with a service to stop that service now in PrepareToInstall.

Cheers,

  Sebastian

Vladimir

unread,
Apr 30, 2021, 8:17:21 PM4/30/21
to innosetup
Hi,
You could use Check function installing the first service file to stop and delete files and AfterInstall to start/install the service with the last service app file. I.e. say you have exe+dll, you stop before installing exe and start after dll.

Gavin Lambert

unread,
May 2, 2021, 5:20:36 PM5/2/21
to inno...@googlegroups.com
On 30/04/2021 6:34 pm, Sebastian P.R. Gingter wrote:
> The update instruction say:
> Stop the service, delete all files, copy over new version, start
> service, done.
>
> My problem: I can't figure out how to do that in this order, without a
> lot of very ugly custom code. The service creates some files in some
> other directories which aren't installed, so the installer doesn't know
> them, still I have to delete them on update.

The correct place to stop the service is in PrepareToInstall in [Code].

You can then use regular [Files] entries to install things, and either
[Run] or CurStepChanged(ssPostInstall) [Code] to start the service again.

Sebastian P.R. Gingter

unread,
May 3, 2021, 1:50:23 AM5/3/21
to innosetup
Yeah, that seems a good approach.

PrepareToInstall in combination with WizardComponentIsSelected(myComponent) is the place to stop the service.
And then CurStepChanged again with WizardComponentIsSelected can be used to re-start the the stopped services in case of an update.

Cheers and thanks for the help!

   Sebastian

Martijn Laan

unread,
May 3, 2021, 8:07:36 AM5/3/21
to inno...@googlegroups.com
Op 30-4-2021 om 08:34 schreef Sebastian P.R. Gingter:
My problem: I can't figure out how to do that in this order, without a lot of very ugly custom code.

You shouldn't need a lot or perhaps any code for this, see https://jrsoftware.org/ishelp/index.php?topic=setup_closeapplications


[InstallDelete] seems too early, as the Windows Service is still running at this point. I can't delete files that are still being accessed.

If you have [InstallDelete] entries deleting files from a service and those files match CloseApplicationsFilter, then the service won't be running at this point because Setup will have stopped it for your automatically.

Greetings,
Martijn
Reply all
Reply to author
Forward
0 new messages