benjy
Posts: 35
Joined: Mon Nov 02, 2009 12:25 pm

Conditionally stopping a service

Hi,

I am building an installer to install our Transport Agent for Exchange Server. As part of the installation process, I'd like to conditionally stop the MSExchangeTransport service, install our DLL, register the DLL (requires two commands to be executed in the Exchange Powershell) and the re-start the MSExchangeTransport service.

I have been able to make some progress:

- I can successfully detect the state of the MSExchangeTransport service: http://www.advancedinstaller.com/user-g ... rvice.html (this is working very nicely)
- I have created a custom dialog that prompts the user if they wish to stop and re-start the service (using the AI_SERVICE_STATE property); this populates a property using a radiobutton group.

However, I am having trouble getting much further. The next step as I see it is to stop the service if the user has so elected. To that end, I was going to use a Launch file as Administrator custom action... I have created the action but I'm unable to insert it anywhere in the Installation Sequence. Ideally, I'd it to go in the Preparing stage. Likewise, I'd like a second custom action in the Finish Execution stage to re-start it. So...

1) How do I insert my Custom Action in these stages? Perhaps I have missed how to use the UI?
2) How can I make my Custom Actions execute conditionally based on the property populated on my dialog?

Next, I'll need to be able to run the two Exchnage Powershell commands to register the Transport Agent:

- Register-TransportAgent ...
- Enable-TransportAgent ...

Could you give me some guidance on how I might accomplish this?

Many thanks,

Ben
benjy
Posts: 35
Joined: Mon Nov 02, 2009 12:25 pm

Re: Conditionally stopping a service

Hi,

I'm making some progress and have reached a point whereby I am trying to stop the service by running sc.exe using a custom action. If I run my installer, I get the following failure:

Code: Select all

MSI (s) (08:B8) [19:06:11:887]: Doing action: StopMSExchangeTransport
Action 19:06:11: StopMSExchangeTransport. 
Action start 19:06:11: StopMSExchangeTransport.
MSI (s) (08:B8) [19:06:11:887]: Note: 1: 1721 2: StopMSExchangeTransport 3: C:\Program Files\Symprex\Email Signature Manager Transport Agent\ 4: "C:\Windows\system32\sc.exe" stop MSExchangeTransport 
Error 1721. There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor. Action: StopMSExchangeTransport, location: C:\Program Files\Symprex\Email Signature Manager Transport Agent\, command: "C:\Windows\system32\sc.exe" stop MSExchangeTransport 
MSI (s) (08:B8) [19:06:12:854]: Product: Symprex ESM Transport Agent for Exchange 2007 & 2010 -- Error 1721. There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor. Action: StopMSExchangeTransport, location: C:\Program Files\Symprex\Email Signature Manager Transport Agent\, command: "C:\Windows\system32\sc.exe" stop MSExchangeTransport 
If I copy-and-paste the command (i.e. "C:\Windows\system32\sc.exe" stop MSExchangeTransport) into a command window, it runs fine. My installer is configured to only run as administrator i.e. it should have the appropriate elevated privileges.

I have tried using a number of different custom actions types; this one is a Launch EXE with working directory command.

Any suggestions?

Thanks,

Ben
Dan
Posts: 4529
Joined: Wed Apr 24, 2013 3:51 pm

Re: Conditionally stopping a service

Hello,

First of all I apologize for my delay reply.
How do I insert my Custom Action in these stages? Perhaps I have missed how to use the UI?
Please note that a custom action can be added as:
“a custom action with sequence” - it will be displayed in the “Installation Sequence” panel.
“a custom action without sequence”. - This is useful if you wish to launch this custom action through an Execute custom action event in Dialogs page.

So, in your case you can have a custom action without sequence and add a “published event” on the control button of the dialog where you want to be executed.
How can I make my Custom Actions execute conditionally based on the property populated on my dialog?
You can use in the “Condition” field the property of the “Radio Button Group” to condition the execution of that custom action.
Please note that the value of the radio button's property will be set to the selected radio button's value.
Let's assume that your radio button group has two choices(e.g. Yes – to stop the service and No – to not stop the service). In the condition field of a custom action you can use something like: RADIOBUTTONGROUP_1_PROP = “Yes” and the related custom action will only be executed when it was chosen “Yes” - radio button.

Then on the [Finish] button you can add a new “Published event” where your custom action to restart the service will be executed. Also you can condition this custom action if the service is stopped.
Also, in order to start a service, you can go in the Services page and add a service control operation using the [New Control Operation] toolbar button. In the “Service Name” label type the service name that you want to start. The service will start almost to the end of the installation process.
I'm making some progress and have reached a point whereby I am trying to stop the service by running sc.exe using a custom action. If I run my installer, I get the following failure:
I'm not sure why you encountered this behavior.

Please note that you can use our predefined Stop service custom action.

I have attached a .zip archive containing a sample which implement a similar scenario.
You have a “detect service” custom action. If the service is running is displayed a custom dialog to the user there he can choose to stop or not. If he choose to stop the service then the “Stop service” custom action will be executed.
If the service is not running then the related custom dialog is not displayed.

If you need any help, please let me know.

Best regards,
Dan
Attachments
Detect Service and Stop Service.zip
(197.11 KiB) Downloaded 384 times
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”