How to install a system service without permission errors - wix

I am getting the following error when running my installer a secondary PC, but it works when i run it on my development machine.
MSI (s) (90:2C) [16:22:35:704]: Executing op: ServiceInstall(Name=PCR2,DisplayName=Amusoft PC Remote 2,ImagePath="C:\Program Files\Amusoft\PC Remote 2\web\Amusoft.PCR.Server.exe",ServiceType=16,StartType=2,ErrorControl=32771,,Dependencies=[~],,StartName=LocalSystem,Password=**********,Description=Backend service required for PC Remote to interact with this computer,,)
InstallServices: Service:
Error 1923. Service 'Amusoft PC Remote 2' (PCR2) could not be installed. Verify that you have sufficient privileges to install system services.
This is my fragment for installing and starting the service
<Fragment>
<Component Id="RegistrySetValues" Guid="CCA1011E-0C44-4111-9089-A4F5D49D3D51" Win64="yes" Directory="WEBFOLDER">
<RegistryKey Root="HKLM" Key="SOFTWARE\Amusoft\PC Remote 2" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
<RegistryValue
Type="string"
Name="InstallLocation"
Value="[PRODUCTNAMEFOLDER]"/>
<RegistryValue
Type="string"
Name="Version"
Value="$(var.ProductVersion)"/>
</RegistryKey>
</Component>
<Component Id='BackendServerExe' Guid='7B39D2A5-140F-452D-BAEC-0B965A15CCC9' Directory='WEBFOLDER'>
<File Id='BackendServer' Name='Amusoft.PCR.Server.exe' Vital='yes' Source='$(var.SolutionDir)..\artifacts\msi\web\Amusoft.PCR.Server.exe' KeyPath='yes'/>
<fire:FirewallException
Name='Amusoft PC Remote 2 Server'
Id='BackendServerFirewall'
Port='[CUSTOM_PORT]'
Protocol='tcp'
Profile='all'
Scope='localSubnet'
IgnoreFailure='no'
Description='Amusoft PC Remote 2 Server'/>
<ServiceInstall Name='$(var.ServiceName)'
Type='ownProcess'
Start='auto'
Account="LocalSystem"
DisplayName="Amusoft PC Remote 2"
Id="PCR2.Install"
Description="Backend service required for PC Remote to interact with this computer"
Vital="yes" ErrorControl="critical">
<!-- Vital="yes" ErrorControl="critical"> -->
<util:ServiceConfig
FirstFailureActionType="restart"
SecondFailureActionType="restart"
ThirdFailureActionType="none"
ResetPeriodInDays="1"
ServiceName="$(var.ServiceName)"
RebootMessage="PC Remote 2 requires a reboot"
RestartServiceDelayInSeconds="180"
/>
</ServiceInstall>
<!-- <ServiceControl Id="PCR2.Control.Start" -->
<!-- Name="$(var.ServiceName)" -->
<!-- Start="install" -->
<!-- Wait="no" /> -->
<ServiceControl Id="PCR2.Control.Stop"
Name="$(var.ServiceName)"
Stop="uninstall"
Remove="uninstall"
Wait="yes" />
<!-- <ServiceControl Id="PCR2.Control" -->
<!-- Name="$(var.ServiceName)" -->
<!-- Remove="both" -->
<!-- Start="install" -->
<!-- Stop="both"/> -->
</Component>
</Fragment>
I looked at these questions, but that did not fix my issue
How to install and start a Windows Service using WiX
Wix installer: Verify that you have sufficient privileges to start system services
Is this related to strong name signing? I don't understand why it works on my dev machine, but fails on a secondary machine

Solution: The .NET 5 hosting runtime was missing.
Lacking Runtime: Typically you lack a runtime if the service starts on your dev-computer and not on the test box. Common lacking
runtimes: .Net, .Net Core, Java, VC++ Runtime, MS-XML (legacy), etc... Virtual machines often lack most runtimes in their base state, and this is a very common problem when testing setups.
Debug Binaries: Another variation of the above is to install debugging binaries that depend on completely different runtime files than the release version files. These debugging binaries are the binaries built when you use the "Debug" configuration in your Visual Studio project. They depend on dlls with "d" added to their file names (C++).
Other Ideas: There are many other potential causes. Here are some check lists for application and service launch failures:
Crash on Launch
Application Launch Problems
Bitness: One should mention bitness as another "first issue" to check (x86 vs x64 binaries - incompatibilities and confusion).
Other Links:
Tools for dependency scanning your binaries
Windows Services Frequently Asked Questions (FAQ)
General debugging links of various types

Related

WIX: Installing a service - AppId entries ignored/too late?

I have been attempting to create an installer using WIX (3.10.1.2213).
I am installing a Windows Service that uses DCOM.
I have a component that uses ServiceInstall and ServiceControl to do what I require.
However I am having issues when it comes to the AppId entries.
If I use the following...
<AppId Id="{REALGUID}" Advertise="no" Description="MyDescription" LocalService="MyService" ServiceParameters="-Service" />
...My installation fails when attempting to start the service - with the ever helpful "...failed to start. Verify that you have sufficient privileges to start system services".
However, if I add the registry entries manually - outside of WIX (even by exporting the entries that WIX creates - so they are definitely the same) - the installation succeeds.
Does anyone know what could be happening here?
In summary, WIX creates the entries I expect, but installation fails.
If I export these entries and start from scratch, merge the entries into the registry and rerun the installer, it succeeds.
I have attempted to move the AppId entry to other locations in the wxs file. I have also attempted to manually set the registry entries using <RegistryValue...>, but it appears to have the same result (I see the entries get created, but the service fails to start).
I'm not sure if this is relevant, but this service requires another entry under HKCR\AppID\{GUID} which I do create using <RegistryValue...>. I'm not sure if that is somehow causing a conflict and I can't currently debug the service as it doesn't get far enough.
Also, from here, I see...
If this element is nested under a Fragment, Module, or Product
element, it must be advertised.
But I don't fully understand it. Does it mean if 'directly' nested under...?
Or could this be my problem and my wxs file could be ordered badly, because I need registry entries instead of being Advertised?
It is currently something like this...
<Fragment>
<Directory...>
<Component...>
<File...>
<AppId...>
<RegistryValue...>
<ServiceInstall...>
<ServiceControl...>
I am very confused - but hopefully missing something obvious.
Hopefully someone can shed some light on it for me.
Regards,
Ads.
If it helps, here is an edited extract of the component in question...
<Component Id="ServiceControl" Guid='REALGUID' >
<File Id="MyApplication.exe" Name="MyApplication.exe" KeyPath="yes" Vital="yes" Source="$(var.MyApplication.TargetDir)\MyApplication.exe" />
<AppId Id="{REALGUID}" Advertise="no" Description="MyApplication" LocalService="MyApplication" ServiceParameters="-Service" />
<RegistryValue Root="HKCR" Key="AppID\{REALGUID}" Name="Group" Value="[GROUP]" Type="string" Action="write" />
<ServiceInstall
Id="ServiceInstaller"
Type="ownProcess"
Name="MyApplication"
DisplayName="My Application"
Description="Some Description"
Start="auto"
Account="LocalSystem"
Interactive="yes"
ErrorControl="normal"
Vital="yes" >
<ServiceDependency Id="[FTPSERVICE]" />
</ServiceInstall>
<ServiceControl Id="MyApplication" Name="MyApplication" Start="install" Stop="uninstall" Remove="uninstall" Wait="yes" />
</Component>

How to wait for a file being installed to GAC before installing a service with wix

I'm using Wix to create my application installer and using it to install an assembly in the GAC and it works fine.
My issue is when I'm setting the assembly property 'copy local=false' and I'm executing the installation, then my services is not being installed cause it can't find this dll in the local folder and it's not being installed to GAC yet.
If I'll install another component from the EXE installation and will verify that the DLL is in the GAC I will be able then to install the service.
I'm using Paraffin.exe to go all over my application directory and generate a wix file and also using Mold file to add component not from this directory.
<DirectoryRef Id="Manager">
<Component Id="NlogGACRegisterComponent" Guid="1B224CD1-6EE8-46D3-9335-A84B7D8FB87B">
<File Id="NlogDLL" Name="Nlog.DLL" Source="..\Logging\Nlog.DLL" KeyPath="yes" Vital="yes" Assembly=".net"/>
</Component>
<Component Id="ManagerServiceComponent" Guid="EA31E161-4331-4A82-8F2B-7E26F62C96D6">
<File Id="StateManagerServiceEXE" Name="ManagerHostService.exe" DiskId="1" Source="..\ManagerHostService.exe" KeyPath="yes" Vital="yes" />
<ServiceInstall Id="ServiceInstaller" Type="ownProcess" Name="ManagerHostService" DisplayName="Manager Service" Description="Manager Service" Start="auto" Account="[SERVICEACCOUNT]" Password="[SERVICEPASSWORD]" ErrorControl="normal">
<util:PermissionEx User="Everyone" GenericAll="yes" ServiceChangeConfig="yes" ServiceEnumerateDependents="yes" ChangePermission="yes" ServiceInterrogate="yes" ServicePauseContinue="yes" ServiceQueryConfig="yes" ServiceQueryStatus="yes" ServiceStart="yes" ServiceStop="yes" />
</ServiceInstall>
<ServiceControl Id="StartService" Start="install" Name="ManagerHostService" Stop="both" Remove="uninstall" Wait="yes" />
</Component>
</DirectoryRef>
This in the Mold file which responsible to install the DLL to GAC and then the service.
How can I make sure it first install the DLL's and then the service?
All files and Dlls ARE installed by the time that services are started. Look in your MSI file with Orca at the InstallExecuteSequence (or look in a verbose log) and you'll see that InstallServices and StartServices are after InstallFiles.
The issue is that assemblies aren't installed and available in the GAC until InstallFinalize, this is described here:
https://msdn.microsoft.com/en-us/library/aa370063(v=vs.85).aspx
where it says "This means you cannot use the ServiceControl Table to start the service, instead you must use a custom action that is sequenced after InstallFinalize." which is what you'll need to do.

How can I automate registration of an ATL service?

I have a project that includes an ATL service. Currently, our installer registers the service with custom actions that run the installed service executable with the command:
MyService.exe /server
and unregisters it with the command
MyService.exe /unregservice
This has caused headaches in some situations where the command has failed and the installation becomes stuck in a state where it can neither be completed or fully rolled back, leaving the application unusable.
We would like to replace these custom actions by using the ServiceInstall tag to do the registration completely within the MSI file, but we can't get it to work. Our initial code looked like this:
<Component Id="c.MyService.exe" Guid="{PUT-GUID-HERE}">
<File Id="f.MyService.exe" Name="MyService.exe" KeyPath="yes"
DiskId="1" Source="$(var.MyService.TargetPath)" Vital="yes" />
<ServiceInstall Id="svci.MyService" Name="MyService" Type="ownProcess"
Start="demand" ErrorControl="normal" DisplayName="MyService"
Description="My Service" Account="LocalSystem" Interactive="no"
Vital="yes">
<ServiceDependency Id="RPCSS"/>
</ServiceInstall>
<ServiceControl Id="svcc.MyService" Stop="both" Remove="uninstall"
Name="MyService" Wait="yes" />
</Component>
The install would complete, but running the program failed with this message:
Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 80040152 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
One suggestion found via google was to add in the AppId tag inside the Component tag as follows:
<Component ... />
...
<AppId Id="$(var.MyServiceGUID)" LocalService="MyService" Description="MyService" />
...
</Component>
However this didn't have any effect.
Any ideas how to replicate the ATL's self-registration in the MSI itself?
For reference, I believe I am having the same problem as in this ancient, unanswered post: http://social.msdn.microsoft.com/Forums/vstudio/en-US/eb33cf47-628a-4fbf-a740-f81afe2f2b43/atl-service-install-and-registration-issue-com-server-vs-windows-service?forum=vcgeneral
Thanks very much
WiX has a program called Heat that can be used to harvest the COM metadata for your ATL server. Run this program to generate a wxs fragement, migrate the COM elements to your wxs fragement then rebuild and test on a clean snapshotted VM. Rinse and repeat if needed as COM/ATL is a little tricky at times.
Harvest Tool (Heat)

Windows service not getting installed on major upgrade-WIX

I have my service installed on the machine by an msi package(WIX). But when an major upgrade is done,service gets uninstalled but it doesnt get installed.
This is my code:
<Component Id="abc" Guid="{E64A8CDD-816F-4544-9ACD-A2E367F7758A}">
<File Id="EventTraceService.exe" Source="..\..\..\..\Products\abc.exe" Vital="yes" KeyPath ="yes"/>
<File Source="..\..\..\..\Products\abc.exe.config" Vital="yes" />
<ServiceInstall
Id="ServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="abc"
DisplayName="abc"
Description="Monitoring and management of Trace"
Start="auto"
Account="LocalSystem"
Interactive="yes"
ErrorControl="normal"
/>
<ServiceControl Id="StartService" Start="install" Stop="uninstall" Remove="uninstall" Name="abc" Wait="yes" />
Thanks in advance!
One possible explanation is that you changed the GUID of the component. As a result, (the different versions of) the same resources are being managed by different components.
From the windows installer documentation about what happens when the component rules are broken:
An author includes the same resource in two different components.
If two components have a resource under the same name and location and both components are installed into the same folder, then the removal of either component removes the common resource, which damages the remaining component.
Uninstalling either component removes the resource and breaks the other component.
The component reference-counting mechanism is damaged.
This seems to match your symptom.
If the service EXE has the same version in both packages, this happens because of the file versioning rules. Here is an article with more details: http://setupanddeployment.com/windows-installer-bugs/missing-files-upgrade/

Wix Installer ignores elevated privileges when updating

Although the first installation works fine, when I try to update the application to a newer version, the installer presents the following message:
Service X could not be installed. Verify that you
have sufficient privileges to install system services.
When cancelling the update installation, the software is removed and if I install again, the process finishes successfully.
I'ts important to say that both install and update are requiring elevation of privilege.
Any ideas?
Elevation of Privilege
<Package InstallerVersion="300"
Compressed="yes"
InstallScope="perMachine"
InstallPrivileges="elevated"
AdminImage="yes" />
Service configuration:
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="X"
DisplayName="X"
Description="X"
Start="auto"
ErrorControl="normal" />
<ServiceControl Id="StartService"
Start="install"
Stop="both"
Remove="uninstall"
Name="X" Wait="yes" />
I can be many thing. I suggest to try couple of things.
-set account
<ServiceInstall Account="NT AUTHORITY\LocalService" />
-Install the MSI package. When the error dialog comes up do not dismiss the dialog. Start services.msc or use sc.exe from the command-line to attempt to start your service. If necessary debug into your service executable directly to see why it cannot be started.
Summery from Failed to install and start Windows services in WiX installer
-Ensure that it does not depend on files being placed in the GAC.
-Use event viewer to check the error.
-What is the name of the service? there is limitation on naming the service.
-if the service is already exist it can give you that insufficient privileges error, check that the service is uninstalled before installing again. Should be part of the upgrade procedure.
Hope it will get you started.