WiX: Installing Service as LocalService
Asked Answered
L

10

17

I am trying to get my application an installer via WiX 3.0. The exact code is:

<File Id="ServiceComponentMain" Name="$(var.myProgramService.TargetFileName)" Source="$(var.myProgramService.TargetPath)" DiskId="1" Vital="yes"/>

<!-- service will need to be installed under Local Service -->
<ServiceInstall
                        Id="MyProgramServiceInstaller"
                        Type="ownProcess"
                        Vital="yes"
                        Name="MyProgramAddon"
                        DisplayName="[removed]"
                        Description="[removed]"
                        Start="auto"
                        Account="LocalService"
                        ErrorControl="ignore"
                        Interactive="no"/>
<ServiceControl Id="StartDDService" Name="MyProgramServiceInstaller" Start="install" Wait="no" />
<ServiceControl Id="StopDDService" Name="MyProgramServiceInstaller" Stop="both" Wait="yes" Remove="uninstall" />

Thing is, for some reason LocalService fails on the "Installing services" step, and if I change it to "LocalSystem" then the installer times out while trying to start the service.

The service starts fine manually and at system startup, and for all intents and purposes works great. I've heard there are issues getting services to work right under LocalService, but Google isnt really helping as everyone's responses have been "got it to work kthx".

Just looking to get this service set up and started during installation, that's all. Any help? Thanks!

Lebkuchen answered 11/7, 2009 at 20:47 Comment(1)
You might want to check this thread (see very last post): windows-installer-xml-wix-toolset.687559.n2.nabble.com/… It would seem you need to have the KeyPath set on the file and have the file in the same component.Overburden
C
16

Make sure the services.msc window is closed when you install

Cumber answered 1/11, 2012 at 8:6 Comment(2)
O M F G. Really? I need a break.Asafetida
actually even if the services tab of the task manager is open for another user on the same server this is enough to prevent installation.Cumber
D
10

Have you tried ...

NT AUTHORITY\LocalService 

Per this doc ...

... but the name of the account must be NT AUTHORITY\LocalService when you call CreateService, regardless of the locale, or unexpected results can occur.

Disenthrone answered 11/7, 2009 at 20:53 Comment(4)
I think I tried that, but as "Local Service". Will try without.Lebkuchen
With Account="NT AUTHORITY\LocalService", I get the following: "Error 1923. Service 'My Program Long Name' (MyProgramAddon) could not be installed. Verify that you have sufficient privileges to install system services." Thing is, the installer is running as an administrator under Windows XP. I am confused :-(Lebkuchen
I'm doing this on Windows 8. Without NT AUTHORITY\, it fails immediately. When I use NT AUTHORITY\LocalService, it takes several minutes and I see the service get farther in the services.msc snap in (it gets to Starting as its Status), but it still fails all the same. Any ideas?Cassiani
Helped in my case.Penoyer
S
8

reference: ServiceControl Table

The MSI documentation for ServiceControl Table states that the 'Name' is the string name of the service. In your code snipet, your ServiceControl 'Name' is set to the 'ID' for the ServiceInstall and not its 'Name'. So, your ServiceControl elements should read:

<ServiceControl Id="StartDDService" Name="MyProgramAddon" Start="install" Wait="no" />
<ServiceControl Id="StopDDService" Name="MyProgramAddon" Stop="both" Wait="yes" Remove="uninstall" />
Semivitreous answered 24/7, 2009 at 19:21 Comment(0)
C
7

Here is another case where a localsystem service can fail to install with error 1923: if you have another service already installed with the same DisplayName (but different internal service name, path, etc). I just had this happen to me.

Cabaret answered 21/5, 2011 at 22:15 Comment(0)
C
4

I spent a while looking into this and discovered it was because I had the keypath attribute set on the the component not on the file. My wix file now looks like:

<Component Id="comp_WF_HOST_18" DiskId="1" KeyPath="no" Guid="3343967A-7DF8-4464-90CA-7126C555A254">
    <File Id="file_WF_HOST_18" Checksum="yes" Source="C:\Projects\GouldTechnology\Infrastructure\WorkflowHost\WorkflowHost\bin\Release\WorkflowHost.exe" KeyPath="yes"/>

      <ServiceInstall
                 Id="workflowHostInstaller"
                 Type="ownProcess"
                 Vital="yes"
                 Name="WorkflowHost"
                 DisplayName="Workflow Host"
                 Start="demand"
                 Account="[WORKFLOW_HOST_USER_ACCOUNT]"
                 Password="[WORKFLOW_HOST_USER_PASSWORD]"
                 ErrorControl="critical"
                 Interactive="no"/>
    <ServiceControl Id="StartWFService" Name="workflowHostInstaller" Start="install"  Stop="both" Remove="both" Wait="no" />

</Component>

Now I just need to work out how to give it the correct permissions...

Chet answered 15/1, 2010 at 11:23 Comment(1)
Thanks. KeyPath="yes" on my .exe and "no" on other executables fixed the issue! This is a huge help!Mayman
G
3

I had the same problem. It turns out that I had a typo in the <ServiceControl Id="StartService" Name="MyServiceName" where my Name did not match the service name I specified in the service project when I created it.

This was also the problem with my service not uninstalling.

Goner answered 25/5, 2010 at 22:16 Comment(0)
D
2

Had the same problem but with specified accounts, got bored of it and created a CA to start the service after the install was completed instead. Just don't bother trying to start it with MSI, just leave it to a CA, unless you get some quality info from somewhere.

BTW using LocalSystem and a manually started service works fine. Never got any other variations to work.

Diffusivity answered 26/7, 2009 at 15:28 Comment(2)
@DanCsharpster: Custom Action, a kind of add-on for Windows Installer jobs. msdn.microsoft.com/en-us/library/aa368066%28v=vs.85%29.aspx Previously they had to be written in C++, but it should now be possible to write them in C#. advancedinstaller.com/user-guide/qa-c-sharp-ca.htmlPickings
Oh, gotcha. Thanks! Yeah, I've written a few custom actions for the VS2010 installer and they work pretty well once you learn the tricks and what not. Sorry, I just didn't think to turn that into an acronym.Cassiani
P
2

I'll just echo aristippus303's advice: Don't try to start a service with Windows Installer, and don't set any account, just accept the default of LocalSystem during installation. Trying to do anything else is too problematic. Windows Installer waits for the service to indicate it has started, and there are too many things that can go wrong, what with permissions and rights and firewall settings and missing files and so on, so then Windows Installer ends up frozen or terminating with an error and your install has failed.

What you want to do is to specify in your documentation that the user should manually change the service's account (if necessary) and manually start the service after the install is done, and to trouble-shoot any problems that turn up at that point. Or just tell the user to reboot so the auto-start option will start the service if you're fairly sure that there won't be problems.

Pickings answered 4/2, 2011 at 14:3 Comment(1)
By the way, another problem situation is that if your service is a .Net program, and if you're installing assemblies to the GAC, then you can't start the service in Windows Installer because the GAC has not yet been populated when the attempt to start the service occurs.Pickings
S
1

Please pay attention that in the documentation for ServiceInstall element it is written about the Account attribute that "The account under which to start the service. Valid only when ServiceType is ownProcess.". In your example you did not specify the ownProcess service type which may be the problem.

Septillion answered 10/11, 2009 at 17:2 Comment(1)
Hi, It does run under OwnProcess. I retyped the code by hand and I guess I forgot that directive. Thanks though!Lebkuchen
S
1

We had the same problem occuring only on Windows XP machines were the service could not be installed. In the end we found that on XP the name setting from the WiX file is ignored and it instead used the service name set in the C# code. We happened to have a name in the code that contained white-space, i. e. "Blah Blah Service", when this was set to the same name as the WiX file used on Windows 7 it worked well.

Soothfast answered 13/10, 2010 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.