How to install and start a Windows service under a NetworkService account using WiX?


I am trying to create a wix installer to install and start a Windows Service under NetworkService account, but failed, what I got is "Service"() could not be installed. Verify that you have sufficient privileges to install system services."

Please advice, my code is as below:

<Component Id="service" Guid='myguid'>
          <File Id='JobServiceEXE' Name='JobService.exe' DiskId='1' Source='mypath\JobService.exe' KeyPath='yes' />
          <ServiceControl Id="JobService" Name="[SERVICEID]" Stop="uninstall" Remove="uninstall" Wait="yes" />
          Id="JobService" Name="[SERVICEID]" DisplayName="[SERVICENAME]" Type="ownProcess"  Start="auto" ErrorControl="normal" Vital ='yes'
          Account="NT Authority\NetworkService"
          Description="Job Service" />

Thank you!

First, the message you're getting may be due to a security issue. Your installer must be run by an administrator because creating services requires administrative privileges. You might check for that in a Condition element.

Second, using NT Authority\NetworkService as the account name will fail on non-English systems, because built-in account names are localized. Instead, use plain old NetworkService which Wix recognizes specially and resolves into the correct localized name.