Files
2018-06-29 19:47:36 +00:00

61 lines
1.9 KiB
C#

using System.Collections.Generic;
using System.ServiceProcess;
using System.Text;
using System.Reflection;
namespace GeneratorService
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
if (args.Length > 0)
{
if (args[0] == "-i")
{
ServiceInstaller si = new ServiceInstaller();
si.InstallService(Assembly.GetExecutingAssembly().Location, "AyaNovaGenerator", "AyaNova generator service");
}
else if (args[0] == "-u")
{
//Attempt to stop the service first
ServiceController sc = new ServiceController("AyaNovaGenerator");
if (sc.Status == ServiceControllerStatus.Running)
if (sc.CanStop)
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped, new System.TimeSpan(0,0,30));//wait max 30 seconds to stop then just proceed anyway
sc.Dispose();
ServiceInstaller si = new ServiceInstaller();
si.UnInstallService("AyaNovaGenerator");
}
} else
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new AyGenSrv() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
//ServiceBase[] ServicesToRun;
//// More than one user Service may run within the same process. To add
//// another service to this process, change the following line to
//// create a second service object. For example,
////
//// ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
////
//ServicesToRun = new ServiceBase[] { new AyGenSrv() };
//ServiceBase.Run(ServicesToRun);
}
}
}