Stop service at uninstall on Win 7 with UAC on from WIX - 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]

Related

Problems Wix Installer on Windows Server 2016

I've a Wix 3.10 installer with 3 Windows Service, when i run the MSI in my local PC (Windows 8) the Services are installed correctly. I can Stop, Start and too Unistall the Services with the MSI.
The problem is when I install the MSI on Windows Server 2016, I can't Stop and Unistall the service. The Xml of the Wix Installer is the Next.
<ServiceInstall
Id="WindowsService"
Name="Service"
DisplayName="My windows Service"
Description="Process text Files and moves them into Database"
Type="ownProcess"
Vital="yes"
Start="auto"
Account="[WIX_ACCOUNT_LOCALSERVICE]"
ErrorControl="critical"
Interactive="no"/>
<ServiceControl
Id="ServiceControl"
Name="Service"
Start="install"
Stop ="both"
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.

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.