Mykhailo Seniutovych
Mykhailo Seniutovych

Reputation: 3681

How to start a windows service after ExitDialog in WIX

I want to have a checkbox in ExitDialog, and based on it start or do not start a windows service I installed. I tried to do it using a custom action that executes command line to start a windows service, this is my WIX code:

<Fragment>
    <!--This is the custom action to start my windows service, note there is pause in ExecuteCommand to see the output of command line --> 
    <CustomAction Id='LaunchApp' Directory='INSTALLFOLDER' Execute='immediate'
              ExeCommand='[SystemFolder]cmd.exe /C net start MyService &amp; pause' Return='ignore'/>
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch My Windows Service" />

    <UI Id="Custom_InstallDir">
      <!--Here I start windows service if the checkbox is checked--> 
      <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApp" Order="998">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
      <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>

      <!--Some other code-->
    </UI>
  </Fragment>

When I install my application and mark the checkbox to run windows service I get this error: Access is deniedm this is probably because the action is immediate and not deffered, but I can't run deffered custom action in this case.

Is there any way to overcome my problem?

Upvotes: 1

Views: 504

Answers (1)

PhilDW
PhilDW

Reputation: 20780

You can't do that from an immediate custom action because an immediate CA does not run elevated. Your custom action would need to be deferred and no-impersonate so that it runs elevated, and before InstallFinalize.

In my experience many customers don't want this sort of tweak, so why not just start the service in the usual way? Or if they choose not to start it and there is an app associated with the service, then perhaps have some UI in there to start or stop the service (which again will require elevation).

Is the service configured to start after a reboot? I assume it is, otherwise the user will always need to start it.

Upvotes: 3

Related Questions