ServiceInstall or ServiceControl Problem - wix

During Installation, I'm installing my service using ServiceInstall and ServiceControl tags. But, my service is not running. I'm getting error message "Please check you have sufficient privilege to start service". But, I'm in Administrators group. I'm using Wix ver 3.0.
code snippet is here,
<File Id='myexe' Name='myexe.exe' DiskId='1'
Source='myexe.exe' Vital='yes'>
</File>
<ServiceInstall Id='myService' DisplayName='MySampleService'
Name='MySampleService'
ErrorControl='normal' Start='auto'
Type='ownProcess' Vital='yes' />
<ServiceControl Id="StartService"
Name="MySampleService" Start="install" Wait="yes" />
<ServiceControl Id="StopService" Name="MySampleService"
Stop="both" Wait="yes" Remove="uninstall" />
Please help me.

That is the generic error you get when the service fails to install or start (if you are telling it to do that) for any reason. It is very frustrating. The only way to debug is slowly remove dependencies until things finally work. More often than not, the service requires some code (an assembly in the GAC?) that isn't fully configured until later.
I usually debug by looking at the Services.msc and trying to start the service while the error message is up. That typically provides better error messages than the Windows Installer does.

do not try to start .NET Services depending on Components being installed into the Global Assembly Cache GAC, ServiceStart comes too early for that

You could also examine Window Eventlog to identify the problem. If the problem is a missing binary the you can use Depends to find out what is missing.

Try to use util:User element
for example:
<util:User Id="myServiceUser" Name="[USERNAME]" LogonAsService="yes" UpdateIfExists="yes" CreateUser="no"
FailIfExists="no" />

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 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)

Wix installer always install my service under Local System Account

I am creating wix installer for windows service.
But my windows service is not getting installed under the service account which I pass instead it always installed under Local System Account. Please help.
<Component Id="MySImporterService" Guid="{3EA5076C-C3FA-4A5F-95A5-365C6919DEB4}" KeyPath="yes">
<ServiceInstall Id="MyInstall"
Type="ownProcess"
Name="MyService"
DisplayName="MyService"
Start="auto"
Account="[SERVICE.USERNAME]"
Password="[SERVICE.PASSWORD]"
ErrorControl="normal" />
<ServiceControl Id="MyControl"
Stop="both"
Remove="uninstall"
Name="MyService"
Wait="no"/>
</Component>
It seems clear that (as Cole suggests) the values for SERVICE.USERNAME and SERVICE.PASSWORD are not correct. Those identifiers are Windows Installer properties that need to resolve to valid accounts at install time. A verbose log will show if they are getting set correctly.
Another issue may be that the install might get a repair, and that will result in re-install of the service so those properties would need to be available at that time as well as at install time.
Edit: Make sure that the property names are marked Secure=Yes in your WiX, otherwise they won't get preserved properly into the Execute sequence.

Stop service at uninstall on Win 7 with UAC on from WIX

How can i stop my service at uninstall in Win7 or Vista with UAC on from WIX?
When i uninstall my service from Control Panel in Win7 or Vista with UAC on I always get "File is in use message". How can i stop it so that message won't appear?
I have this code in Wix:
<ServiceInstall Id='MyServiceInstall' DisplayName='OnPremises Gateway' Name='OPGatewayService'
ErrorControl='normal' Start='auto' Type='ownProcess' Vital='yes' Account='NT AUTHORITY\NetworkService' />
<ServiceControl Id="StartOPGatewayServiceControl" Name="OPGatewayService" Wait="no" Start="install" />
<ServiceControl Id="StopOPGatewayServiceControl" Name="OPGatewayService" Stop="both" Wait="yes" Remove="uninstall"/>
Thank you,
Adriana
Unfortunately, the "File in use" detection is early. Check out the MSI SDK documentation about their interaction: http://msdn.microsoft.com/en-us/library/aa372466(VS.85).aspx
After investigating more about this, the solution is to use a program at uninstall (like Uninstall.exe) which requires admin rights from user before any actions that imply system changes (like stop service). And from that program run MsiExec.exe /X[MsiProductId]

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.