Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wix MSI package : for Windows service

Error : Creating new installer using WiX toolset, for windows service. Not able to install the service. Getting an error
Error screenshot

Environment

  • Microsoft visual studio 2017
  • Windows 7
  • WiX toolset v3 : Setup project for MSI

Problem/Goal

I want to create a MSI which installs a Windows service.

On Install :

Windows service gets installed and visible in services.msc

On UnInstall:

Stop and Remove the service.

My windows service has lot of dependencies which are to be used when running the service.

I have added all the files as component and added ServiceDependency for each of the component ID also, but still not able to resolve the error. The error in the event viewer is also the same as the above screenshot.

Any pointers are most welcome.

My Code

    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <Feature Id="ProductFeature" Title="LayoutSwitcher" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
    </Feature>
</Product>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="LayoutSwitcher" />
        </Directory>
    </Directory>
</Fragment>

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">

  <Component Id="PlcmLayoutSwitcherWinSvc.exe" Guid="PUT_GUID_HERE" KeyPath="yes">
            <File Id="LayoutSwitcherWinSvc.exe" 
 Name="LayoutSwitcherWinSvc.exe" Source="$(var.LayoutSwitcherWinSvc_TargetDir)LayoutSwitcherWinSvc.exe" />

    <CreateFolder />
    <ServiceInstall Id="LayoutSwitcher" Type="ownProcess" Vital="yes" 
                    Name="LayoutSwitcher" DisplayName="LayoutSwitcher" 
                    Description="LayoutSwitcher" Start="auto" Account="NT AUTHORITY\LocalSystem" 
                    ErrorControl="ignore" Interactive="no">
   <ServiceControl Id="StartService" Start="install" Stop="both" 
    Remove="uninstall" Name="LayoutSwitcher" Wait="yes" />
  </Component>
    <Component Id="logoicon.ico" Guid="PUT_GUID_HERE">
        <File Id="logoicon.ico" Name="logoicon.ico" Source="$(var.LayoutSwitcherWinSvc_ProjectDir)logoicon.ico" />
     </Component>
     <Component Id="LayoutSwitcherWinSvc.exe.config" Guid="PUT_GUID_HERE">
     <File Id="LayoutSwitcherWinSvc.exe.config" Name="LayoutSwitcherWinSvc.exe.config" Source="$(var.LayoutSwitcherWinSvc_TargetDir)LayoutSwitcherWinSvc.exe.config" />
  </Component>
  <Component Id="Transactions.dll" Guid="PUT_GUID_HERE">
    <File Id="Transactions.dll" Name="Transactions.dll" Source="$(var.LayoutSwitcherWinSvc_TargetDir)Transactions.dll" />
  </Component>
  <Component Id="Transactions.Cfg.dll" Guid="PUT_GUID_HERE">
    <File Id=" Transactions.Cfg.dll" Name="Transactions.Cfg.dll" Source="$(var.LayoutSwitcherWinSvc_TargetDir) Transactions.Cfg.dll" />
  </Component>

EDIT :1

Updated the source code after removing the service dependency, but still getting the same error.

EDIT :2

Removed the whitespaces, but still getting the same error.

EDIT :3

Verbose logs attached. Please download from the below link.
http://www.yourfilelink.com/get.php?fid=1432133

like image 224
alrightyy Avatar asked Nov 01 '17 11:11

alrightyy


People also ask

How do I create an MSI file with WiX?

Adding a WiX setup project In Visual Studio, open your solution, and add a WiX project to it: go to the Visual Studio main menu and click File -> Add -> New Project to open the Add New Project dialog. Choose the Setup Project item in the Windows Installer XML node, specify the project name and click OK.

What is WiX Installer used for?

Windows Installer XML Toolset (WiX, pronounced "wicks"), is a free software toolset that builds Windows Installer packages from XML. It consists of a command-line environment that developers may integrate into their build processes to build MSI and MSM packages.

How do I know if I have WiX toolset installed?

You can also check in the Programs and Features section of Control Panel. If WiX Toolset is installed, it will be listed there. If you need to install WiX Toolset, you can download it from here.


2 Answers

Can you try this piece of wix code? I cleaned it a little bit to remove some default values.

Unless you want to place the file with a different filename you don't need the Name attribute.

If you want your service to run as Local System then you need to set empty Account. If you want it to run as a specific user then you could set the properties on your command line SVCACCOUNT=someuser SVCPASSWORD="password", otherwise just skip them.

If Name and Id is the same then you can skip the Id.

I prefer to use variables for things that I use in multiple places to avoid typos, for example ServiceName that is used in ServiceInstall and ServiceControl I use:

<WixVariable Id="ServiceName" Value="LayoutSwitcher" />

<Component Id="PlcmLayoutSwitcherWinSvc.exe" Guid="PUT_GUID_HERE">
  <File Id="LayoutSwitcherWinSvc.exe" Source="$(var.LayoutSwitcherWinSvc_TargetDir)LayoutSwitcherWinSvc.exe" KeyPath="yes" />
  <ServiceInstall Name="!(wix.ServiceName)"
                  DisplayName="LayoutSwitcher"
                  Description="LayoutSwitcher"
                  ErrorControl="ignore"
                  Type="ownProcess" 
                  Vital="yes"
                  Start="auto"
                  Account="[SVCACCOUNT]"
                  Password="[SVCPASSWORD]" 
                  Interactive="no" />
  <ServiceControl Id="ServiceControl_!(wix.ServiceName)"
                  Name="!(wix.ServiceName)"
                  Start="install"
                  Stop="both"
                  Remove="uninstall"
                  Wait="yes" />
</Component>

The log you attached is incomplete, run the installer all the way through and attach the log only after you've closed the installer. IMO Debug log is not necessary.

like image 162
IlirB Avatar answered Sep 21 '22 08:09

IlirB


Try making both of the Name attributes exactly the same in the install and the control. They need to match exactly and they don't. You're trying to start a non-existent service.

like image 37
PhilDW Avatar answered Sep 20 '22 08:09

PhilDW