Using WiX to install and start a Windows Service as part of your Add-In install is fairly easy. The only thing you really have to watch out for is the KeyPath value for your service executable; it has to be set to yes, while all other file KeyPaths must be set to no.

Make sure you also use your own GUID values for UpgradeCode and Component ID values.

This code works with the latest WiX 3.0 weekly build.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product
    Name="Windows Home Server Disk Management Add-In"
    Id="*"
    UpgradeCode="{EB6B8302-C06E-4bec-ADAC-932C68A3A98D}"
    Manufacturer="Sam Wood - Tentacle Software"
    Version="1.1.0.0"
    Language="1033">
    <Package
      Manufacturer="Sam Wood - Tentacle Software"
      InstallerVersion="200"
      Languages="1033"
      Compressed="yes" />

    <Media Id="1" Cabinet="WHSDiskManagement.1.1.0.0.cab" EmbedCab="yes" />

    <Property Id="WHSLogo">1</Property>

    <Condition Message="[ProductName] requires Windows Home Server. For more information, please refer to the User Guide.">VersionNT = 502</Condition>

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder" Name="PFiles">
        <Directory Id="WHS" Name="Windows Home Server">
          <Component Id="HomeServerConsoleTab.DiskMgt" Guid="{908B7199-DE2A-4dc6-A8D0-27A5AE444FEA}">
            <File Id="HomeServerConsoleTab.DiskMgt.dll" Name="HomeServerConsoleTab.DiskMgt.dll" Source="..\HomeServerConsoleTab.DiskMgt\bin\Release\HomeServerConsoleTab.DiskMgt.dll" Vital="yes" KeyPath="no" DiskId="1"/>
            <File Id="DiskMgt.Common.dll" Name="DiskMgt.Common.dll" Source="..\DiskMgt.Remotable\bin\Release\DiskMgt.Common.dll" Vital="yes" KeyPath="no" DiskId="1"/>
            <File Id="DiskMgt.Service.exe" Name="DiskMgt.Service.exe" Source="..\DiskMgt.Service\bin\Release\DiskMgt.Service.exe" Vital="yes" KeyPath="yes" DiskId="1"/>
            <ServiceInstall
              Id="ServiceInstaller"
              Type="ownProcess"
              Vital="yes"
              Name="DiskManagement"
              DisplayName="Windows Home Server Disk Management"
              Description="Monitoring and management service for Windows Home Server Disk Management Add-In"
              Start="auto"
              Account="LocalSystem" 
              ErrorControl="ignore" 
              Interactive="no"
              >
              <ServiceDependency Id="QSM"/>
              <ServiceDependency Id="pdl"/>
              <ServiceDependency Id="WHSTransportService"/>
            </ServiceInstall>
            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="DiskManagement" Wait="yes" />
		  </Component>
	    </Directory>
	  </Directory>
	</Directory>

	<Feature Id="ProductFeature" Title="WHSDiskManagement" Level="1">
      <ComponentRef Id="HomeServerConsoleTab.DiskMgt" />
	</Feature>
  </Product>
</Wix>

ServiceDependency values are the real names for the services your code depends on. You can find the Service Name by opening services.msc and checking the properties for the specific service.

The ServiceControl node allows you to start and stop services during install and uninstall.

In the example above, I’m controlling a service called DiskManagement (the service I’m installing in the parent ServiceInstall node, but it could be any service). The service is started after the MSI package has been installed, stopped (if it’s started, to allow me to overwrite or delete the service’s files) at the beginning of both install and uninstall operations, and removed at the end of an uninstall operation.

The Service Control Id value is just an identifier that you can use to refer to this specific ServiceControl node in other places in the XML.

If you want to use extended character sets (for localization into different languages, usually) in the various display and description fields, you’ll need to set the xml encoding value and Product Codepage appropriately. I’ve also set the Product Language and Package Languages to German in this example:

<?xml version="1.0" encoding="Windows-1252"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product
    Name="Windows Home Server Datenträger-Verwaltung"
    Id="*"
    UpgradeCode="{EB6B8302-C06E-4bec-ADAC-932C68A3A98D}"
    Codepage="1252"
    Manufacturer="Sam Wood - Tentacle Software"
    Version="1.1.0.0"
    Language="1031">
    <Package
      Manufacturer="Sam Wood - Tentacle Software"
      InstallerVersion="200"
      Languages="1031"
      Compressed="yes" />

There’s some good documentation on the rest of the options (ownProcess, Start type, Account etc.) in the WiX help files that get installed along with the WiX binaries. It’s not the most friendly set of technical docs I’ve seen, but it does give detailed descriptions of the individual configuration elements.

posted on Thursday, January 01, 2009 2:22 PM | Filed Under [ Windows Home Server Development ]

Comments

Gravatar
# re: Installing and starting a Windows Service using WiX (Andrey @ 4/11/2009 1:34 AM)

Many thanks!
Very helpful "Happy New Year" post ))
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Deepthi @ 6/22/2009 6:56 PM)

if the code is
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="37464ddd-2cb8-4ee1-8369-5e3a6f544705" Name="WixProject1" Language="1033" Version="1.0.0.0" Manufacturer="WixProject1" UpgradeCode="8421ea02-f76c-421d-af59-a047299b742c">
<Package InstallerVersion="200" Compressed="yes" />

<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="WixProject1">
<Component Id='TheService' Guid='FF15180D-B296-4F30-9385-0F15B8ACC1FF' KeyPath='yes'>
<File Id='WindowService_Wix' Name='WindowService_Wix.exe' DiskId='1'
Source='D:\deepthi\Coding\Console\WindowService_Wix\WindowService_Wix\bin\Debug\WindowService_Wix.exe'/>
<File Id='readme' Name='readme.txt' DiskId='1' src='D:\deepthi\Coding\Console\WindowService_Wix\WindowService_Wix\bin\Debug\Readme.txt' />

<ServiceInstall
Id="ServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="A"
DisplayName="A"
Description="A"
Start="demand"
Account="[SERVICEACCOUNT]"
Password="[SERVICEPASSWORD]"
ErrorControl="normal"/>
<ServiceControl Id="StartWixServiceInstaller"
Name="A"
Start="install"
Wait="no" />
<ServiceControl Id="StopWixServiceInstaller"
Name="A"
Stop="both"
Wait="yes"
Remove="uninstall" />

</Component>
</Directory>
</Directory>
</Directory>

<Feature Id="ProductFeature" Title="WixProject1" Level="1">
<ComponentRef Id='TheService'/>
</Feature>
</Product>
</Wix>

then also it's not instaaling a service "A" can u please solve this issue?
 
Gravatar
# re: Installing and starting a Windows Service using WiX (administrator @ 6/22/2009 7:01 PM)

Hi Deepthi,

Without actually trying to compile the source you've provided, I'd guess that part of the problem is the multiple ServiceControl elements in your code, and the missing KeyPath values for your files (as noted in the top of this post).

A good idea might be to take my working example and replace the files with the ones you want to install, and customize the XML from there.

 
Gravatar
# re: Installing and starting a Windows Service using WiX (Praveen @ 11/17/2009 7:12 PM)

Hi
I need to start the service only after setting some configuration files. The code you provided is starting immediately after installing service. Can you give a solution other than a custom action?

Regards

Praveen
 
Gravatar
# re: Installing and starting a Windows Service using WiX (me @ 1/16/2010 8:30 PM)

its very helpful for me thanks mesaman
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Elisabeth Yusnita A @ 2/19/2010 3:42 PM)

Hi ,

I have some question related with this topic
Here is my problem:
I have application that needs Apache Tomcat to be installed before application run. First, i try to install jakarta-tomcat-5.0.28.exe via bootstrapper, but i wait for more than 10minutes and nothing happens, wizard dialog from Tomcat doesn't show up.
Then i try another way to install tomcat using <ServiceInstall> just like your code above, the result is service success to install without any dialog wizard shown, my expectation is tomcat wizard dialog will shown so i can configure what i need to configure just like install another exe using bootstrapper.

Please advice how to install this tomcat.exe properly. with dialog wizard from tomcat show up and i configure the setting of the apache properly. Thanks a lot

Best regards,


Elisabeth
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Siva @ 3/13/2010 2:22 AM)

Hi,

I tried your fragment, its giving the following error while installation, do i need to have any special permission to install the service?

Service 'Test Service' (Test Service) failed to start. Verify that you have sufficient privileges to start system services?

Note: I'm administrator in the system and i right clicked the msi and chose run as administrator option

Thanks in Advance
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Mike Bulava @ 4/24/2010 4:19 AM)

I too am having issues getting services to install. Same error "Service 'Test Service' (Test Service) failed to start. Verify that you have sufficient privileges to start system services?" there isn't anything wrong with the service I've gotten it to install using the old VS Project Installer class method...
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Krishna Mohan @ 5/13/2010 1:47 AM)

I am also facing same issues in windows service, While trying to install .msi
It showing this Errro : Fail to start. Verify that you have sufficient privileges to start system service. (Note: I have Administrator rights in our machine, Using Windows XP).

Some one please provide me a solution.

 
Gravatar
# re: Installing and starting a Windows Service using WiX (Burnt OUt from WIX @ 9/4/2010 1:52 AM)

Got this error as well
Above service install method worthless.
Fail to start. Verify that you have sufficient privileges to start system service. (Note: I have Administrator rights in our machine, Using Windows XP).
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Fredster @ 9/5/2010 2:42 PM)

Failed to start for me as well. Back to drawing board. Hope I figure it out before I get fired. Project behind schedule now. Thanks WIX...
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Mart @ 11/24/2010 5:34 AM)

Is it just me or is WIX like going back a decade
 
Gravatar
# re: Installing and starting a Windows Service using WiX (rgrenfell @ 4/28/2011 9:20 AM)

I ran into the service start issue as well. It turned out when I used msiexec.exe -i MyInstaller.msi /l*v dumpfile.txt to dump what was happening that I discovered that what the code above attempts to "install" as the service is actually the first <File> element in the <Component>. Even the example above would have this issue.

If you simply put your Windows Service executable as the last File element then the ServiceInstall block code example for WiX works as advertised.

This may help out future readers of this article.
 
Gravatar
# re: Installing and starting a Windows Service using WiX (marc @ 10/4/2011 4:16 AM)

example works like a charm, many thanks.
For those who do not want the service to start after successful installation, just get rid of the Start="install" attribute.
 
Gravatar
# re: Installing and starting a Windows Service using WiX (jason @ 2/2/2012 9:08 AM)

I agree with marc.
The only way I could stop the failed to start message was to make it so the service does not start on install. (i.e. get rid of start = "install" attribute)
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Peter Hegelund @ 5/1/2012 8:29 PM)

start is not optional in my world (WIX 3.5) so instead of removing it, I intend to set it to "disabled"
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Ajay Rao @ 9/25/2012 6:08 PM)

I had a service that was supposed to write a logging message whenever it started or stopped to this location "C:\results\result.txt"

Initially the above program failed with the same error - saying "... <your service> failed to start. Verify that you have sufficient privileges to start system services" .

Later when i manually created the results folder before installation , the above code worked perfectly, and install log showed successful installation of my service file. Services snap-in showed my service is started and the result.txt contained proper logging too.

I guess, if your service tries to use resources of the system (in this case a folder named "result") and the same is unavailable, the service will fail to start, as a result, the installer will return an error code and roll back the installation.
 
Gravatar
# re: Installing and starting a Windows Service using WiX (Joel Palmer @ 10/5/2012 5:53 PM)

I am getting the same "Not authorized" error using Visual Studio 2012 and Wix 3.6 Windows Service Startup Project. I deleted the Startup="Install" tag and the program installed. However, not without errors. Can someone explain to me how this may impact the installer?

I never wanted to be a MSBuild expert but this is now required of me. The latest video on Channel9 that give me anything of substance on this topic was done in 2006. Can we get an updated video using an updated version of this product?
 
Gravatar
# re: Installing and starting a Windows Service using WiX (asha @ 4/20/2013 5:14 PM)

I am facing issues in windows service, While trying to install, and get this Errro : "Fail to start. Verify that you have sufficient privileges to start system service. "

Post Comment

Title *
Name *
Email
Url
Comment *  
Remember me
Please add 2 and 4 and type the answer here:

Search

Site Sections

Recent Posts

Archives

Post Categories

WHS Add-In Tutorial

WHS Blogs

WHS Development