pgarofalo
Posts: 9
Joined: Wed Apr 22, 2009 3:38 pm

Stopping and Starting a Service Not Part of the Install

Hello there, I would like to stop a service at the beginning of a setup and then restart it when the installation is complete. The service is not part of my application's setup package. It may already be present and started on the target machine. Everything I've seen so far in the AI documentation refers to services that are part of the installation. Is there a way that I can control a service that is not part of the installation? Put another way, I'd like run "net stop aService" (ignoring any errors) at the begining and then "net stop aService" (again ignorning any returned errors) at the end. I would do that but it isn't clear to me how to invoke a DOS command at the beginning or end either. Please advise.

Thanks,

Phil Garofalo
PMA Consultants, LLC
Chicago, IL
pgarofalo
Posts: 9
Joined: Wed Apr 22, 2009 3:38 pm

Re: Stopping and Starting a Service Not Part of the Install

This is a follow up to my previous post. 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. Should work, right--or will it? I'm calling it from InatllUISequence/Begin with "stop" and from InstallExecuteSequence/StartServices (ordered after Commit) with "start". Of course, I'd pefer to call the net.exe that's already on the target PC to avoid any potential OS incompatabilities. Is that possible?

Regards,

Phil Garofalo
pgarofalo
Posts: 9
Joined: Wed Apr 22, 2009 3:38 pm

Re: Stopping and Starting a Service Not Part of the Install

One more complication to my attempt at using an attached custom action: the second call to net.exe fails, despite the first call apparently working (or at least didn't stop the install if it did fail). Both calls are set to ignore the return code. I'm not sure if I'm on the right track or if there's a more straightforward way of controlling services.

Thanks,

Phil
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Stopping and Starting a Service Not Part of the Install

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
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pgarofalo
Posts: 9
Joined: Wed Apr 22, 2009 3:38 pm

Re: Stopping and Starting a Service Not Part of the Install

Thanks Cosmin. Some follow-up questions however.

On the Services page, under Control Operations, I added a new control operation. You state that this will enable me to control services that already exist on the target machine. However, I don't see how to specifiy this. The Service Name field is pretty self-explanatory (except there's no indication if names with spaces must be quoted). The Attached Component drop list requires a value. What do I select there? What is AIShRegAnswer? I couldn't find anything in the help on it. I presume this field should be blank, but as it's not a combo-box there's no way to clear it.

Regards

Phil
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Stopping and Starting a Service Not Part of the Install

Hi Phil,
You state that this will enable me to control services that already exist on the target machine. However, I don't see how to specifiy this.
You can specify the service which should be controlled through the "Service Name" field in the "Control Operation Paraneters" pane (the service is indicated through its name).
The Service Name field is pretty self-explanatory (except there's no indication if names with spaces must be quoted).
No, the service name doesn't need to be enclosed by quotes.
The Attached Component drop list requires a value. What do I select there?
The installation package is organized into components and features. You can read more about them here. The "Attached Component" combo allows you to select a component in the package. This component will contain the control operation and it will decide if the operation is used or not (if the component is installed, the operation is used).
What is AIShRegAnswer?
This is a registry entry used by the "ShortcutsDlg" dialog in the "Dialogs" page (it contains the shortcut options chosen by the user). Since it's a registry value, a component is automatically created for it in the "Organization" page.
I presume this field should be blank, but as it's not a combo-box there's no way to clear it.
All resources installed by a MSI package and some of the actions performed by it need to be associated with a component. This is also the case for a service control operation (a component must be used).

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”