Wix Dilemma - is this even possible?
My Aim:
To produce a WiX installer that can stop services before installing its files, install the files and then restart the stopped services
The problem
The names of the services can be different each time the installer is run, but they will always have a prefix (pref开发者_运维百科ix|servicename-servername) e.g
coServSamSs-server1 & coServSpooler-server1
coServSamSs-otherserver2 & coServSpooler-otherserver2.
I can only think that running a powershell script from the installer to start/stop these services would be the most viable option, but the next problem is that I would want to include such powershell scripts in the msi, so is it possible to
- install the script before any other files and then run it to stop the services
- install the rest of the files
- run the script again to restart the services
I know that there are custom activities to run a powershell script, although i have not had any luck in doing so (see Wix - install and then run a powershell script)
Suggestions please? Is what I'm trying to do even possible?
Thanks in advance
You can use custom actions with windows command to stop specific services
<CustomAction Id="A_StopService" Directory="INSTALDIR" ExeCommand='NET STOP "[SERVICENAME]"' Execute="immediate" Return='ignore'></CustomAction>
And as you told you have multiple service, then you can call a custom action written in C# or some other language. Get the list of services with prefix you want and then inside the loop
ServiceController controller = new ServiceController(servicename);
try
{
if (controller.Status == ServiceControllerStatus.Running | controller.Status == ServiceControllerStatus.Paused)
{
controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 0, 12));
controller.Close();
}
}
catch (Exception ex)
{
//Some message
}
Like this stop all the services and once the tasks are done, restart the services.
精彩评论