SoraV2Utils/SoraV2Utils_Service/ServiceInstaller.cs
krjan02 26cde137c9
Some checks failed
Build and Relase / build-release (push) Failing after 38s
Build and Relase / create-release (push) Failing after 10s
Initial commit (1.0.0)
2025-01-13 16:27:29 +01:00

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);
}
}
}
}