licensetrackeragent/MPELicenseAgent/ProjectInstaller.cs

38 lines
1.4 KiB
C#
Raw Normal View History

2024-08-30 14:27:20 -06:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using System.Threading.Tasks;
namespace MPELicenseAgent
{
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
public ProjectInstaller()
{
AfterInstall += serviceInstaller1_AfterInstall;
InitializeComponent();
}
private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
{
using (ServiceController serviceController = new ServiceController(this.serviceInstaller1.ServiceName))
{
if (serviceController.Status.Equals((object)ServiceControllerStatus.Running) || serviceController.Status.Equals((object)ServiceControllerStatus.StartPending))
serviceController.Stop();
serviceController.WaitForStatus(ServiceControllerStatus.Stopped);
serviceController.Start(); // Starts the service
serviceController.WaitForStatus(ServiceControllerStatus.Running);
// Automatic restarts ("Recovery" tab in service properties is sec via the command): +
// sc.exe failure "MPE License Tracker" reset= 0 actions= restart/60000
}
}
}
}