Quantcast
Channel: wixsharp Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1354

New Post: Restarting Windows service and conditional launch

$
0
0
As far as I know neither MSI nor WiX offer functionality for controlling external services (not the ones being installed). Though I can be wrong.

However Wix# allows easy control of any OS component including services. Have a look at WinService_InstallUtil sample. You will need to schedule an elevated custom action and restart your service by either using .NET service API or with sc.exe. Wix#tasks already have sc.exe wrapped:
var project =
    new Project("My Product",
        new Dir(@"%ProgramFiles%\My Company\My Product",
            new File(@"..\SimpleService\MyApp.exe")),
        new ElevatedManagedAction(CustomActions.RestartService, Return.check,
...
[CustomAction]
publicstatic ActionResult RestartService(Session session)
{
    return session.HandleErrors(() =>
    {
        Tasks.StopService("WixSharp.SimpleService", throwOnError:false);
        Tasks.StartService("WixSharp.SimpleService", throwOnError:false);        
    });
}
This can be even easier with Managed Setup:
project.AfterInstall += project_AfterInstall;
...
staticvoid project_AfterInstall(SetupEventArgs e)
{
    Tasks.StopService("WixSharp.SimpleService", throwOnError:false);
    Tasks.StartService("WixSharp.SimpleService", throwOnError:false);
}
As for launch condition I advise you to have a look at Launch Condition sample. In your case that actual condition would be the presence of service exe, or another product being installed and product code being present in registry. I personally prefer to use C# to check the service presence from the event handler and abort the setup if needed.

Viewing all articles
Browse latest Browse all 1354

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>