47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Configuration.Install;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.ServiceProcess;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SoraV2Utils_Service
|
|
{
|
|
[RunInstaller(true)]
|
|
public partial class ServiceInstaller : System.Configuration.Install.Installer
|
|
{
|
|
public ServiceInstaller()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
|
|
{
|
|
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName);
|
|
sc.Start();
|
|
}
|
|
|
|
private void ProjectInstaller_BeforeUninstall(object sender, InstallEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
using (ServiceController sv = new ServiceController(serviceInstaller1.ServiceName))
|
|
{
|
|
if (sv.Status != ServiceControllerStatus.Stopped)
|
|
{
|
|
sv.Stop();
|
|
sv.WaitForStatus(ServiceControllerStatus.Stopped);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
EventLog.WriteEntry("SoraV2Utils_Service", ex.Message, EventLogEntryType.Warning);
|
|
}
|
|
}
|
|
}
|
|
}
|