static void Main(string[] args) { try { if (args != null && args.Any(x => x == "/i")) { InstallService.Install(App.Config.AppName); return; } if (args != null && args.Any(x => x == "/s")) { InstallService.TryStopService(App.Config.AppName); return; } if (Environment.UserInteractive) { var app = new App(); app.Run().Wait(); } else { ServiceBase.Run(new Program()); } } catch (Exception ex) { File.AppendAllText(Path.Combine("C:\\", "failedToStart.txt"), ex.ToString()); } }