user1051307
user1051307

Reputation: 483

WIX Toolset CustomAction to start Windows Service

Is it possible to start my installed Windows Service using a CustomAction? And is it possible to have a CustomAction to change the Start Type of the previously installed Windows Service?

I would really appreciate if anyone could guide me in the right direction!

Upvotes: 1

Views: 3245

Answers (4)

user1051307
user1051307

Reputation: 483

I finally placed a checkbox in the InstallDirDlg and based on its value I decided whether to use a Component with a ServiceInstall element with Start='auto' or to use a Component with a ServiceInstall element with Start='demand'. This solved my first problem. But I couldn't use the ServiceControl Element to start the service because this would start the service directly after the installation and my service needs to be configured before it can work properly. So I finally ended up to start my Service from my source code. That way I was able to use a CustomAction that was fired on the ExitDialog 'Finish'-Control.

Upvotes: 0

Sunil Agarwal
Sunil Agarwal

Reputation: 4277

Here a sample code which I am using for starting service directly from WIX custom action

<CustomAction Id="StartWinService" Directory="INSTALLLOCATION" ExeCommand='NET START "[SERVICENAME]"' Execute="immediate" Return="ignore" />

Upvotes: 0

PhilDW
PhilDW

Reputation: 20790

You could write custom action code to start a service, yes, and being a C++ guy I would use the Win32 StartService API. But why do this? Windows Installer will do this with the StartServices action, with the WiX ServiceControl element. The only reason I know of to start a service with a CA after (say) InstallFinalize is because it has dependencies (assemblies in the GAC or Win32 SxS) that are not committed until after StartServices action.

The recommended way to change the start type is with the WiX ServiceConfig element.

Upvotes: 1

Christopher Painter
Christopher Painter

Reputation: 55601

Guiding you in the right direction would be to advise you that custom actions are inappropriate for this. You can use the Registry element/table to change an existing service's start type and you can use the ServiceControl element/table to start a service you didn't install.

Upvotes: 0

Related Questions