davidpricedev
davidpricedev

Reputation: 2237

How to run something just before the files are installed?

I would like to know how to run something just before files are installed using NSIS.

I know about the .onInit function. That function runs when the installer is first starting. That is not what I want. I would like to run something after the user has clicked the install button but before the files actually get installed.

To be more specific. I have a windows service. When the installer is upgrading the windows service, I need it to stop the service - but only once the user is committed to the install - not when first starting the installer. Then it can upgrade the files and finally (re)start the service again. This seems like it should be a common requirement, but I haven't been able to find anything.

If it matters I'm using the MUI instead of classic.

Upvotes: 1

Views: 751

Answers (2)

Slappy
Slappy

Reputation: 5472

As Anders said - create invisible (hidden) section which is very first of all sections in your script and stop the service there.

When the other sections will be executed the service will be stopped.

Tip: maybe you should wait few seconds to let service manager time to stop the service.

Upvotes: 0

Anders
Anders

Reputation: 101636

All sections are executed on the instfiles page and they are executed in the same order as your source .nsi so you can just add another (hidden) section:

Section
# Do service stuff...
SectionEnd

Section "Required Files"
File xyz.abc
SectionEnd

Section
# Do service stuff...
SectionEnd

Upvotes: 3

Related Questions