Wix installer always install my service under Local System Account - wix

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.

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>

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.

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]

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.