/// <summary> /// The main entry point for the application. /// </summary> private static void Main(string[] args) { if (args != null && args.Length == 1 && args[0].Length > 1 && (args[0][0] == '-' || args[0][0] == '/')) { switch (args[0].Substring(1).ToLower()) { case "install": case "i": SelfInstaller.InstallMe(); break; case "uninstall": case "u": SelfInstaller.UninstallMe(); break; default: Console.WriteLine("Provide parameter to .exe file. Eg. KeplerServiceInstaller.exe -install (or -uninstall for deinstallation)"); break; } } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new KeplerServiceHost() }; ServiceBase.Run(ServicesToRun); } }
private static bool Run(string exeArg, string[] startArgs) { switch (exeArg.ToLower()) { case ("i"): SelfInstaller.InstallMe(); return(true); case ("u"): SelfInstaller.UninstallMe(); return(true); case ("r"): RunAsConsole(); return(true); case ("c"): RunAsController(startArgs); return(true); default: Console.WriteLine("Invalid argument!"); return(false); } }
private static void Main(string[] args) { if (args != null && args.Length > 0) { if (args[0].Equals("-i", StringComparison.OrdinalIgnoreCase)) { SelfInstaller.InstallMe(); return; } else if (args[0].Equals("-u", StringComparison.OrdinalIgnoreCase)) { SelfInstaller.UninstallMe(); return; } else if (args[0].Equals("-c", StringComparison.OrdinalIgnoreCase)) { RunAsConsole(); } else { Console.WriteLine(args[0]); } } else { #if DEBUG if (Debugger.IsAttached == true) { RunAsConsole(); } #else RunAsService(); #endif } }
/// <summary> /// Главная точка входа для приложения. /// </summary> static void Main() { bool isInstalled = false; bool serviceStarting = false; const string serviceName = TextEditorWCFService.CurrentServiceName; ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { if (!service.ServiceName.Equals(serviceName)) { continue; } isInstalled = true; if (service.Status == ServiceControllerStatus.StartPending) { serviceStarting = true; } break; } if (!serviceStarting) { if (isInstalled) { MessageBoxResult dr = MessageBox.Show(string.Format("Do You REALLY Want To Uninstall {0}", serviceName), "Danger", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (dr != MessageBoxResult.Yes) { return; } SelfInstaller.UninstallMe(); MessageBox.Show(string.Format("{0} Successfully Uninstalled", serviceName), "Status", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show( SelfInstaller.InstallMe() ? string.Format("{0} Successfully Installed", serviceName) : string.Format("{0} FAILED To Install", serviceName), "Status", MessageBoxButton.OK, MessageBoxImage.Information); } } else { var servicesToRun = new ServiceBase[] { new TextEditorWCFService() }; ServiceBase.Run(servicesToRun); } }
public static void RunMain(string[] args) { //无参数时直接运行服务 if ((!Environment.UserInteractive)) { RunAsService(); return; } if (args != null && args.Length > 0) { if (args[0].Equals("-i", StringComparison.OrdinalIgnoreCase)) { SelfInstaller.InstallMe(); return; } if (args[0].Equals("-u", StringComparison.OrdinalIgnoreCase)) { SelfInstaller.UninstallMe(); return; } if (args[0].Equals("-t", StringComparison.OrdinalIgnoreCase) || args[0].Equals("-c", StringComparison.OrdinalIgnoreCase)) { RunAsConsole(args); return; } const string tip = "Invalid argument! note:\r\n -i is install the service.;\r\n -u is uninstall the service.;\r\n -t or -c is run the service on console."; Console.WriteLine(tip); Console.ReadLine(); } else { #if DEBUG RunAsConsole(args); #endif } }
//http://superuser.com/questions/465726/run-windows-services-without-administrator-privileges /// <summary> /// The main entry point for the application. /// </summary> static void Main() { bool _IsInstalled = false; bool serviceStarting = false; // Thanks to SMESSER's implementation V2.0 string SERVICE_NAME = Utility.Name; var service = ServiceController.GetServices().FirstOrDefault(i => i.ServiceName.Equals(SERVICE_NAME)); if (service != null) { _IsInstalled = true; if (service.Status == ServiceControllerStatus.StartPending) { // If the status is StartPending then the service was started via the SCM serviceStarting = true; } } if (!serviceStarting) { if (_IsInstalled) { // Thanks to PIEBALDconsult's Concern V2.0 DialogResult dr = new DialogResult(); dr = MessageBox.Show("Do you REALLY like to uninstall the " + SERVICE_NAME + "?", "Danger", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { if (SelfInstaller.UninstallMe()) { MessageBox.Show("Successfully uninstalled the " + SERVICE_NAME, "Status", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Impossible to uninstall", "Danger"); } } } else { DialogResult dr = new DialogResult(); dr = MessageBox.Show("Do you REALLY like to install the " + SERVICE_NAME + "?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { if (SelfInstaller.InstallMe()) { MessageBox.Show("Successfully installed the " + SERVICE_NAME, "Status", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("The service should be run under administration rights", "Danger"); } } } } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); } }
protected override void InstallWindowsService() { SelfInstaller.InstallMe(_exePath); Console.WriteLine("Windows服务安装完成"); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { try { //#if DEBUG bool _IsInstalled = false; bool serviceStarting = false; string SERVICE_NAME = ConfigurationManager.AppSettings["ServiceName"]; ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { if (service.ServiceName.Equals(SERVICE_NAME)) { _IsInstalled = true; if (service.Status == ServiceControllerStatus.StartPending) { // If the status is StartPending then the service was started via the SCM serviceStarting = true; } break; } } if (!serviceStarting) { if (_IsInstalled == true) { // Thanks to PIEBALDconsult's Concern V2.0 DialogResult dr = new DialogResult(); dr = MessageBox.Show("Uninstall " + SERVICE_NAME + "?", "UnInstall " + ConfigurationManager.AppSettings["ServiceName"], MessageBoxButtons.YesNo, MessageBoxIcon.Stop); if (dr == DialogResult.Yes) { SelfInstaller.UninstallMe(); MessageBox.Show("Successfully uninstalled the " + SERVICE_NAME, ConfigurationManager.AppSettings["ServiceName"], MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { DialogResult dr = new DialogResult(); dr = MessageBox.Show("Install " + SERVICE_NAME + "?", "Install " + ConfigurationManager.AppSettings["ServiceName"], MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { SelfInstaller.InstallMe(); MessageBox.Show("Successfully installed the " + SERVICE_NAME, ConfigurationManager.AppSettings["ServiceName"], MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { // Started from the SCM System.ServiceProcess.ServiceBase[] servicestorun; servicestorun = new System.ServiceProcess.ServiceBase[] { new Service1() }; ServiceBase.Run(servicestorun); } //#endif } catch (Exception ex) { Log.LogData("main function in program.cs: " + ex.Message + ex.StackTrace, Log.Status.Error); } //ServiceBase[] ServicesToRun; //ServicesToRun = new ServiceBase[] //{ // new Service1() //}; //ServiceBase.Run(ServicesToRun); }