Configure service to Delayed Auto-Start (and Auto-start on XP/2003) - wix

I have a WiX script, that does installation of service. I have following ServiceInstall element under Component.
<ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes"
Name="abc" DisplayName="abc service"
Description="It does this" Start="auto"
Account="LocalSystem" ErrorControl="normal" Interactive="no">
<ServiceConfig DelayedAutoStart="yes" OnInstall="yes" OnReinstall ="yes" />
</ServiceInstall>
And as seen from the code, I am using ServiceConfig with DelayedAutoStart flag to set the service to start in delayed auto start mode. However the WiX compiler (candle.exe) triggers a warning:
warning CNDL1150: ServiceConfig functionality is documented in the
Windows Installer SDK to "not [work] as expected." Consider replacing
ServiceConfig with the WixUtilExtension ServiceConfig element.
Hence, I tried using util:ServiceConfig^, however this element doesn't have any attribute to control service startup.
^ Namespace import:
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
Hence, the questions are simply:
How to set service startup to be Automatic (Delayed Start)?
How to conditionally do it only on Vista and above, and do normal (Automatic) on Windows XP/2003?

After checking the source it does not seem possible at the moment. Wix calls the ChangeServiceConfig2 function only with the SERVICE_CONFIG_FAILURE_ACTIONS parameter and not with SERVICE_CONFIG_DELAYED_AUTO_START_INFO.
If I was you, I'd write a custom action calling sc config abc start=delayed-auto in a CMD.
As for your second question add VersionNT version condition (VersionNT >= 600 for all version greater than Vista)

Related

Error 1079: Error in restarting windows service

I have developed windows service installer using Wix. Service is set for auto start after installation. The installer has custom dialog which will take user input and updates .config file. The input is optional.
When the input is not provided, config file is not updated.I can restart windows service from services.msc. If user provides input, a custom action(deferred) will update config file. This custom action runs with Impersonate="no" mode.
In this case, windows service auto starts after installation and everything works fine. But when I restart the service, it throws below error.
Below is the code to install service:
<Component Id="CMPFa85281c3_a329_4a93_a1d7_203fbccec31f" Guid="*" Directory="INSTALLLOCATION">
<Condition>
<![CDATA[Installed OR (SVCINSTALL <> 0)]]>
</Condition>
<RemoveFile Id="RmFa85281c3_a329_4a93_a1d7_203fbccec31f" Name="MyService.exe" On="both" />
<File Id="Fa85281c3_a329_4a93_a1d7_203fbccec31f" Source="$(var.BaseDir)\MyService.exe" KeyPath="yes" />
<ServiceInstall Id="InstallWindowsService" Name="MyService"
DisplayName="MyService"
Start="auto"
ErrorControl="normal"
Type="ownProcess"
Account="[USER_DOMAIN]\[SERVICEUSER]"
Password="[PASSWORD]"
Description="MyService"/>
<ServiceControl Id="sc_InstallWindowsService" Name="MyService"
Start="install" Remove="uninstall" Stop="both" Wait="no"/>
</Component>
Below is the code for custom action.
<CustomAction Id="UpdateConfigFiles"
Return="check"
Execute="deferred"
Impersonate="no"
BinaryKey="MyCustomAction.dll"
DllEntry="UpdateFilePath"
HideTarget="yes">
</CustomAction>
<InstallExecuteSequence>
<Custom Action="PassData" Before="UpdateConfigFiles">NOT Installed AND NOT PATCH AND NOT REMOVE</Custom>
<Custom Action="UpdateConfigFiles" Before="InstallFinalize">NOT Installed AND NOT PATCH AND NOT REMOVE</Custom>
</InstallExecuteSequence>
Judging from this kind of thing:
https://support.microsoft.com/en-us/kb/2478117
the error can be associated with insufficient privilege to start the service. There's no reason for the custom action or the configuration step to have an effect unless of course it causes the service to start with a new account or to cause it to share two services in the same process, which is what the message says. It doesn't seem that this is related to the install because there is no mechanism to cause the effect.
The scenario to reproduce is still not clear to me, but it seems that the install can start the service (and the install runs with local system account) so it succeeds, but the error message according to the KB article means that the user attempting to start it doesn't have enough privilege, and otherwise the error says the process is trying to use two accounts, perhaps one in the config file and one that the install configures.

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.

ServiceInstall or ServiceControl Problem

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" />

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.