v 1.0.3 - on setup automaticaly add the service and start it
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System.ComponentModel;
|
||||
using System.Configuration.Install;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.ServiceProcess;
|
||||
|
||||
namespace serviceInstaller
|
||||
{
|
||||
[RunInstaller(true)]
|
||||
public class ProjectInstaller : Installer
|
||||
{
|
||||
private ServiceProcessInstaller processInstaller;
|
||||
private ServiceInstaller serviceInstaller;
|
||||
|
||||
public ProjectInstaller()
|
||||
{
|
||||
processInstaller = new ServiceProcessInstaller
|
||||
{
|
||||
Account = ServiceAccount.LocalSystem
|
||||
};
|
||||
|
||||
serviceInstaller = new ServiceInstaller
|
||||
{
|
||||
ServiceName = "Log4GraylogService",
|
||||
DisplayName = "Log 4 Graylog Service",
|
||||
Description = "Service for monitoring and sending log files to Graylog",
|
||||
StartType = ServiceStartMode.Automatic
|
||||
};
|
||||
|
||||
Installers.Add(processInstaller);
|
||||
Installers.Add(serviceInstaller);
|
||||
}
|
||||
|
||||
public override void Install(System.Collections.IDictionary stateSaver)
|
||||
{
|
||||
base.Install(stateSaver);
|
||||
|
||||
string assemblyPath = Context.Parameters["assemblypath"];
|
||||
string exePath = Path.Combine(Path.GetDirectoryName(assemblyPath), "console_log4graylog.exe");
|
||||
|
||||
using (ServiceController sc = new ServiceController(serviceInstaller.ServiceName))
|
||||
{
|
||||
if (sc.Status == ServiceControllerStatus.Stopped)
|
||||
{
|
||||
Process.Start("sc", $"config \"{serviceInstaller.ServiceName}\" binPath= \"{exePath}\"");
|
||||
Process.Start("sc", $"start \"{serviceInstaller.ServiceName}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user