How to run something just before the files are installed? - nsis

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.

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

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.

Related

Changing restart message on Inno Setup Prepare To Install page

I am building an installer in Inno Setup v6.2.1 with prerequisites, which include .NET, runtimes, and KB fixes (Windows 7 SP1). The goal is to do potentially several reboots depending on if the machine is missing KBs or .NET etc.
I am able to achieve what I want so far using PrepareToInstall and can change the text by returning the appropriate string. No problems... however I can't find a way of changing the.
Setup must restart your computer. After restarting your computer, run Setup again to complete the installation of xxxxx
Because I am creating a runonce entry, the installer will automatically run after reboot (which it does). The text "run Setup again" is not relevant in my situation and I want to change the text to say that the installer will continue once you restart.
I have tried to find where to change this text but with no success. I assume that PreparingMemo might be the candidate but no luck or not sure how to use it. Any help would be appreciated.
See Handling and customizing errors and messages in Inno Setup.
This particular message is defined by the PrepareToInstallNeedsRestart message.
You can change it in the [Messages] section:
[Messages]
PrepareToInstallNeedsRestart=Setup must restart your computer. After restarting your computer, the Setup will continue to complete the installation of [name].%n%nWould you like to restart now?
If you need to change the message text dynamically, assign WizardForm.PreparingLabel.Caption. E.g. from CurPageChanged(wpPreparing) event.

NSIS ExecWait not launching secondary installer

I have a basic NSIS installer that is supposed to call a secondary - non-NSIS installer like so:
Section "Install First" SEC01
File "WindowsPathToFile\setup.exe"
DetailPrint "Installing the first Thing"
ExecWait '"$INSTDIR\setup.exe"'
SectionEnd
NSIS and the installer do not throw any errors - however the sub installer is never launched or executed (and the application is never installed).
Note that if I put the call to "setup.exe" in a batch script and launch the batch script this does work. I was just hoping for something more elegant (that doesn't display the command prompt) as I'll have several custom installers that need to be called.
I didn't think that the ExecWait chain issue detailed in "ExecWait Doesn't Wait" would affect me as I don't think my (setup.exe) installer is extracting a secondary installer.
The setup.exe installer is created by LabVIEW and I haven't found good information on what it's doing behind the scenes.
Am I missing something here? Or do I just need to stick with the batch script?
Does the secondary installer require elevation? Do you have RequestExecutionLevel admin in your .nsi?
ExecWait internally calls the CreateProcess Windows API function and it will fail if the child process needs to be elevated by UAC.
If you are going to execute a child process that requires elevation then it is generally recommended that your installer requires elevation as well. If you for some reason don't want to do this then you can use ShellExecWait or ${StdUtils.ExecShellWaitEx}.

In Inno Setup, how to rollback a "verysilent" installation?

I have created an installer using Inno Setup. The installer uses a packaged-in DLL to check availability of a specific device on the target machine. If the device is found, the installation is allowed to finish, otherwise the installation is rolled-back (rollback is done using below lines in script):
if <DeviceNotFound> then
begin
CancelWithoutPrompt := true;
WizardForm.Close;
end;
I have checked that the above check and rollback logic works fine if the setup is run with /silent cmd line param. However, when I use /silent param, the setup displays the Installation progress wizard form.
Also, I found that if I run the above setup in /verysilent mode, then the "DeviceNotFound" check logic works fine but the rollback logic doesn't work and it seems as if rollback logic doesn't get executed at all. Instead of performing rollback, the installer successfully installs.
Now, I have a requirement to run the setup silently so that no window is displayed but it must install or rollback based on device check. Therefore, I have the below queries:
Can I rollback the installer when it is running in /verysilent mode? If so, please advise how it may be achieved. I can detect verysilent install mode as shown in question:
How to detect whether the setup runs in very silent mode?
Alternatively, can I Hide/Minimize the Installation progress window when it is running in /silent mode? If so, please advise how it may be achieved.
Please help me with my above queries.
Sorry to be so descriptive but I tried to explain my problem and queries!
EDIT
I am not doing the above mentioned check in InitializeSetup(). I am doing the check from a function invoked by AfterInstall directive from [Files] section. I have a limitation that I cannot do it from InitializeSetup() as the packaged-in DLL is not extracted till [Files] section completes. I also need to run the installer in Windows PE (Preinstallation Environment), hence I cannot use ExtractTemporaryFile() function to forcefully extract the DLL because the {tmp} path is not valid in that environment. That leaves me with only one option is to check after [Files] section is done. Please advise!
Your constraint on not using ExtractTemporaryFile does not make sense.
The Inno Setup installer always creates a temporary folder for the installation.
2015-07-31 09:02:07.458 Created temporary directory: C:\Users\martin\AppData\Local\Temp\is-1CN29.tmp
If it is not possible to create the folder, the installation fails.
The Inno Setup tries to create the temporary folder in these locations:
%TMP%
%TEMP%
%USERPROFILE%
Windows installation folder (C:\Windows)
At least the last path has to exist even in the "Windows PE".
So I do not think, there's anything preventing you from using the ExtractTemporaryFile function.

How to start batch file using nsis script?

I have successfully created exe file using NSIS.I have installed my application as windows service using following code:
Exec "$INSTDIR\bin\batch.bat"
I have checked this path
Start Menu -> Control Panel -> Administrative Tools -> Services.
My service name successfully installed.
Final step of my installation process start the application using following code:
!define MUI_FINISHPAGE_RUN net start servicename
But this code did not working well.If i select the checkbox it does not start the services.
My scenario is:
Final step of my installation process is, I have one checkbox.If the user select checkbox then the service started immediately.else dont start the service.but both the cases the service must be installed.How to solve this?
How to start the service using nsis scrit?
The correct code would be:
!define MUI_FINISHPAGE_RUN net
!define MUI_FINISHPAGE_RUN_PARAMETERS "start servicename"
or if you want to put the net command in a batch file or otherwise hide the console window, see this answer to one of your old questions...

how to create server exe for OpenERP version 6.1?

I want to create server exe for OpenERP version 6.1 for Windows. I already created it but the problem is it doesn't have functionality like OpenERP version 6.0 exe server. For e.g. Start Service, Stop Service, View log, Uninistall. How to add all these functionality?
Thanks.
I haven't done it myself, but the process is documented in the OpenERP developer book. It looks like the step you're interested in is this:
makensis setup.nsi
If you look in the setup.nsi file, you can see that it's doing something with the services.
Section -StopService
nsExec::Exec "net stop openerp-server-6.1"
sleep 2
SectionEnd

Resources