mirror of
https://github.com/donavon04/MPELicenseAgent.git
synced 2025-01-18 00:50:57 -07:00
38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
|
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
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|