Hi Phil,
I would like to stop a service at the beginning of a setup and then restart it when the installation is complete.
For this you can use a
Service Control Operation in the
Services page. In the "Event On Install" section you can set the "
Start" and "
Stop" options. This way the service will be stopped by the "InstallExecuteSequence" -> "StopServices"
standard action and it will be started by the "InstallExecuteSequence" -> "StartServices" standard action.
Is there a way that I can control a service that is not part of the installation?
Yes, service control operation can control services which are already present on the machine.
I'm attempting a solution by putting in an attached custom action, using net.exe taken from the system32 directory on my XP SP3 development computer.
Please note that it is not recommended to attach system executables to an installation package. Instead, you can call the executable present on the target machine. For example, you can use an
Exe with Working Dir custom action which runs this command:
Code: Select all
cmd.exe /Q /C "net stop <service_name>"
where you replace "<service_name>" with the name of the service.
I'm calling it from InatllUISequence/Begin with "stop" and from InstallExecuteSequence/StartServices (ordered after Commit) with "start".
Since stopping and starting a system service requires Administrator privileges, the custom actions should run as
Deferred with no impersonation. This option can be set only for custom actions scheduled between "InstallExecuteSequence" -> "InstallInitialize" and "InstallExecuteSequence" -> "InstallFinalize". In this case, the recommended approach is to use the control operation I mentioned.
Regards,
Cosmin