static void Main(string[] args) { var dir = AppDomain.CurrentDomain.BaseDirectory; var envDir = Environment.CurrentDirectory; Logger.WriteMessage(LogLevel.Trace, $"Program.Main {envDir} Base: {dir}"); Environment.CurrentDirectory = dir; Service = new WinService(); bool consoleRun = Environment.UserInteractive; if (args.Length > 0) { String cmd = args[0].Trim().Trim('-').Trim('/').Trim(); switch (cmd) { case "install": case "i": SelfInstall(); break; case "uninstall": case "u": SelfUninstall(); break; case "console": case "c": consoleRun = true; break; default: consoleRun = true; break; } } if (consoleRun) { Logger.WriteMessage(LogLevel.Info, "Starting Console Service"); Service.Start(args); Console.WriteLine("Press any key to exit"); Console.ReadKey(); Service.Stop(); Logger.WriteMessage(LogLevel.Info, "Stopped Console Service"); } else { System.ServiceProcess.ServiceBase.Run(Service); } }
static void Main(string[] args) { #if TRACE Logger.WriteMessage(LogLevel.Trace, "Program.Main"); #endif WinService service = new WinService(); Boolean consoleRun = Environment.UserInteractive; if (args.Length > 0) { String cmd = args[0].Trim().Trim('-').Trim('/').Trim(); switch (cmd) { case "install": case "i": SelfInstall(); break; case "uninstall": case "u": SelfUninstall(); break; case "console": case "c": consoleRun = true; break; default: break; } } else { if (consoleRun) { Logger.WriteMessage(LogLevel.Info, "Starting Console Service"); service.Start(args); Console.WriteLine("Press any key to exit"); Console.ReadKey(); service.Stop(); Logger.WriteMessage(LogLevel.Info, "Stopped Console Service"); } else { System.ServiceProcess.ServiceBase.Run(service); } } }