using System.Collections; using System.ComponentModel; using System.Configuration.Install; using System.ServiceProcess; namespace Neo.LegitimateLicences.WinService { [RunInstaller(true)] public partial class ProjectInstaller : Installer { public ProjectInstaller() { InitializeComponent(); } //public override void Install(IDictionary stateSaver) //{ // base.Install(stateSaver); //} public override void Commit(IDictionary savedState) { base.Commit(savedState); //UpdateConfig( // Context.Parameters["TargetDir"], // Context.Parameters["DataSource"], // Context.Parameters["DatabaseName"], // Context.Parameters["UserName"], // Context.Parameters["Password"]); var controller = new ServiceController { ServiceName = _serviceInstaller.ServiceName }; if(_serviceInstaller.StartType == ServiceStartMode.Automatic && controller.Status == ServiceControllerStatus.Stopped) { controller.Start(); } controller.Close(); } protected override void OnBeforeUninstall(IDictionary savedState) { var controller = new ServiceController { ServiceName = _serviceInstaller.ServiceName }; if(!(controller.Status == ServiceControllerStatus.Stopped || controller.Status == ServiceControllerStatus.StopPending)) { controller.Stop(); } controller.Close(); base.OnBeforeUninstall(savedState); } } }