Search code examples
windows-serviceswix3.11

WiX Windows Service won't start when Account is not LocalSystem


Converting setup applications to WiX, I am encountering the following phenomenon for a Windows Service application written in C#:

1.) Configuring the main EXE component having the ServiceInstall section assign Account="LocalSystem" the application will install successfully but will not run (-start). It does not have authentication to the database to which it will connect so not too surprising.

2.) Using the installation from item one, I apply the ValidAccount and ValidPassword to the "Log On" tab of properties for the service. The service starts and runs successfully when done manually like this as is expected.

3.) Going back to the Wix project, I change the afforementioned ServiceInstall section to have the same Account="ValidAccount" Password="ValidPassword" used in step 2 and rebuild the MSI file. The installation fails to install with the following log messages just after the ServiceInstall:

InstallServices: Service: 
    Error 1923. Service 'My Service' (MyService.exe) could not be installed. Verify that you have sufficient privileges to install system services.
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 20432 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 13032 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 10548 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 19688 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 6588 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 10132 could not be cancelled. Error: 1168
    MSI (s) (B4:94) [12:54:38:616]: Product: MyService -- Error 1923. Service 'My Service' (MyService.exe) could not be installed. Verify that you have sufficient privileges to install system services.

4.) I have confirmed that the ValidAccount is a member of the Local Administrators group.

5.) I have confirmed that the ValidAccount is added to the "Log on as a service" policies.

6.) I have no GAC dependencies in the service (someone sited that GAC dependencies are added at the very end and could disrupt the installation.)

What am I missing? ... even a do nothing service using LocalSystem is fine. However, it won't install if I set the Account and Password as in the below.

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="TestService.exe" Guid="196BB5E5-F157-4CA2-B740-0A68E1539B7C">
        <File 
          Id="TestService.exe" 
          Source="$(var.TestService.TargetPath)" 
          KeyPath="yes" />
    
        <ServiceInstall 
          Id="TestService.exe" 
          Name="TestService.exe" 
          DisplayName="Test Service"
          Description="This is a test service to test installation with WiX."
          Account="myDomain\myAccount" <!-- using myAccount without the domain yields same failure -->
          Password="myAccountPassword"
          Arguments="-start" 
          Start="auto" 
          Interactive="yes" 
          Type="ownProcess" 
          Vital="yes" 
          ErrorControl="ignore" />

        <ServiceControl 
          Id="TestService.exe" 
          Name="TestService.exe" 
          Stop="both" 
          Start="install" 
          Remove="uninstall" 
          Wait="no" />
      </Component>
    </ComponentGroup>
  </Fragment>

Thanks in advance,

Kent


Solution

  • After a bunch of experimentation, I came up with the answer. It actually appears to be a bug in the WiX Toolset, (version 3.11.2,) but I am not sure if someone did this by design. When you add a Password to the ServiceInstall, the Interactive property MUST be set to "no".

    For some unknown reason, if you set it to "yes" only Accounts that do not require passwords will install.

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
          <Component Id="TestService.exe" Guid="196BB5E5-F157-4CA2-B740-0A68E1539B7C">
            <File 
              Id="TestService.exe" 
              Source="$(var.TestService.TargetPath)" 
              KeyPath="yes" />
        
            <ServiceInstall 
              Id="TestService.exe" 
              Name="TestService.exe" 
              DisplayName="Test Service"
              Description="This is a test service to test installation with WiX."
              Account="myDomain\myAccount" <!-- using myAccount without the domain yields same failure -->
              Password="myAccountPassword"
              Arguments="-start" 
              Start="auto" 
              Interactive="no" <!-- MUST BE NO WHEN PASSWORD IS USED -->
              Type="ownProcess" 
              Vital="yes" 
              ErrorControl="ignore" />
    
            <ServiceControl 
              Id="TestService.exe" 
              Name="TestService.exe" 
              Stop="both" 
              Start="install" 
              Remove="uninstall" 
              Wait="no" />
          </Component>
        </ComponentGroup>
      </Fragment>
    

    Good luck in all your endeavors, Kent