static void RunInteractive(ServiceBase[] servicesToRun, string[] args) { var parameter = string.Concat(args); switch (parameter) { case "--install": ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location }); break; case "--uninstall": ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location }); break; default: Console.WriteLine("Services running in interactive mode."); Console.WriteLine(); var onStartMethod = typeof(ServiceBase).GetMethod("OnStart", BindingFlags.Instance | BindingFlags.NonPublic); foreach (var service in servicesToRun) { Console.Write("Starting {0}...", service.ServiceName); onStartMethod.Invoke(service, new object[] { new string[] { } }); Console.Write("Started"); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Press any key to stop the services and end the process..."); Console.ReadKey(); Console.WriteLine(); var onStopMethod = typeof(ServiceBase).GetMethod("OnStop", BindingFlags.Instance | BindingFlags.NonPublic); foreach (var service in servicesToRun) { Console.Write("Stopping {0}...", service.ServiceName); onStopMethod.Invoke(service, null); Console.WriteLine("Stopped"); } Console.WriteLine("All services stopped."); // Keep the console alive for a second to allow the user to see the message. Thread.Sleep(1000); break; } }
internal static void InstallService(ServiceConfiguration configuration, List <string> serviceArgs) { try { _configuration = configuration; _serviceArgs = serviceArgs; var args = new[] { Assembly.GetEntryAssembly().Location }; ManagedInstallerClass.InstallHelper(args); } catch (Exception ex) { Console.WriteLine("Install falied with: " + ex.Message); } }
static void Uninstall() { try { ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); if (!silent) { MessageBox.Show("Service was uninstalled successfully.", "Service Uninstalled", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception e) { if (!silent) { MessageBox.Show("There was an exception uninstalling the service:\r\n\r\n" + e.Message, "Service Uninstall Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void Install() { EnsureRequiredPermissions(); ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); RegisterHttpListenerPrefix(); SetDefaultDataFolderPermissions(); ConfigureTaskPersistenceProvider(); #if !DEBUG StartService(); #endif }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { if (Environment.UserInteractive) { ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); return; } ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new IPAnnouncer() }; ServiceBase.Run(ServicesToRun); }
static void Install(bool install) { if (Environment.UserInteractive) { if (install) { ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); StartService(ProjectInstaller._ServiceName, 20000); } else { StopService(ProjectInstaller._ServiceName, 12000); ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); } } }
public static bool InstallMe() { try { ManagedInstallerClass.InstallHelper(new string[1] { SelfInstaller._exePath }); } catch (Exception ex) { var message = ex.Message; return(false); } return(true); }
private static void EnsureStoppedAndUninstall() { if (!ServiceIsInstalled()) { Console.WriteLine("Service is not installed"); return; } var stopController = new ServiceController(SystemServiceName); if (stopController.Status == ServiceControllerStatus.Running) { stopController.Stop(); } ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location }); }
public static bool InstallMe() { bool result; try { ManagedInstallerClass.InstallHelper(new string[] { _exePath }); } catch { result = false; return(result); } result = true; return(result); }
private void UninstallSerive() { if (!IsServiceInstalled(serviceName)) { return; } try { ManagedInstallerClass.InstallHelper(new[] { @"/u", servicePath }); System.Windows.MessageBox.Show("Service uninstalled"); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }
public static bool UninstallMe() { try { ManagedInstallerClass.InstallHelper(new string[2] { "/u", SelfInstaller._exePath }); } catch { return(false); } return(true); }
/// <summary> /// Install the service /// </summary> public static void Install() { if (IsServiceInstalled()) { Uninstall(); } ManagedInstallerClass.InstallHelper(new string[] { "/LogFile", Assembly.GetExecutingAssembly().Location }); var sc = new ServiceController(Application.WindowsServiceName); if (sc.Status == ServiceControllerStatus.Stopped) { sc.Start(); } }
public static bool Install(string exePath) { try { if (exePath == string.Empty) { exePath = Assembly.GetExecutingAssembly().Location; } ManagedInstallerClass.InstallHelper(new string[] { exePath }); } catch { return(false); } return(true); }
/// <summary> /// This method starts the service. /// </summary> static void Main(string[] args) { if (System.Environment.UserInteractive) { //Though normally installed via iedusm, this case is here for convenience. if (args.Length > 0) { switch (args[0]) { case "-install": { ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); //starting it as per codemonkey from <https://stackoverflow.com/questions/1036713/automatically-start-a-windows-service-on-install>: //results in access denied (same if done manually, unless "Log on as" is changed from LocalService to Local System //serviceInstaller //using (ServiceController sc = new ServiceController(serviceInstaller.ServiceName)) //using (ServiceController sc = new ServiceController("iedusm")) //{ // sc.Start(); //} break; } case "-uninstall": { ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); break; } case "-delete_self": { IEduP.set_setting("delete_self_enable", "true"); //Deleting manually now doesn't work due to permissions even if caller is administrator cmd and service is stopped and disabled up to 8 seconds earlier: IEdu.delete_self(5); break; } } } } else { //ServiceBase.Run(new ServiceBase[] { new iedup() }); ServiceBase[] ServicesToRun; instance = new IEduP(); ServicesToRun = new ServiceBase[] { instance }; ServiceBase.Run(ServicesToRun); } } //end Main
internal bool Uninstall() { if (_isInstalled) { _logger.Info(string.Format("Uninstallation windows service '{0}'...", _serviceName)); var stopSuccess = Stop(); if (!stopSuccess) { return(false); } var exeFile = Path.Combine(AssemblyDirectory, _serviceFilename); if (!File.Exists(exeFile)) { _logger.Error(string.Format("File '{0}' not found", exeFile)); MessageBox.Show(string.Format("Не удалось найти исполняемый файл: {0}.", exeFile)); return(false); } ManagedInstallerClass.InstallHelper(new[] { "/u", exeFile }); var sp = new Stopwatch(); sp.Start(); while (true) { try { if (sp.ElapsedMilliseconds > 40000) { MessageBox.Show("При удалении Twain@Web возникла ошибка. Попробуйте повторно запустить программу удаления."); return(false); } _service.Refresh(); _status = _service.Status; Thread.Sleep(TimeSpan.FromMilliseconds(500)); } catch (Exception e) { break; } } _isInstalled = false; } _logger.Info(string.Format("Windows service '{0}' was successfully uninstalled", _serviceName)); return(true); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { try { if (Environment.UserInteractive) { ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); } else { ServiceBase.Run(new LogonEventsWatcherService()); } } catch (Exception) { } }
public static void Main(string[] args) { var service = ServiceController.GetServices() .FirstOrDefault(x => x.ServiceName == new ServerService.ServerService().ServiceName); if (service != null) { if (MessageBox.Show(@"The service is already installed. remove it ?", @"confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) { ManagedInstallerClass.InstallHelper(new [] { "/u", typeof(ServerServiceSetup).Assembly.Location }); } return; } ManagedInstallerClass.InstallHelper(new[] { typeof(ServerServiceSetup).Assembly.Location }); }
private void UninstalService() { if (!IsServiceInstalled(serviceName)) { return; } try { ManagedInstallerClass.InstallHelper(new[] { @"/u", servicePath }); MessageBox.Show("Service uninstalled"); } catch (Exception exc) { MessageBox.Show(exc.ToString()); } }
internal static void Main() { System.AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; if (Medo.Application.Args.Current.ContainsKey("Interactive")) { Tray.Show(); ServiceThread.Start(); Tray.SetStatusToRunningInteractive(); Application.Run(); ServiceThread.Stop(); Tray.Hide(); Environment.Exit(0); } else if (Medo.Application.Args.Current.ContainsKey("Install")) { ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); System.Environment.Exit(0); } else if (Medo.Application.Args.Current.ContainsKey("Uninstall")) { try { ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); System.Environment.Exit(0); } catch (System.Configuration.Install.InstallException) { //no service with that name System.Environment.Exit(-1); } } else { if (Environment.UserInteractive) { Tray.Show(); ServiceStatusThread.Start(); Application.Run(); ServiceStatusThread.Stop(); Tray.Hide(); Environment.Exit(0); } else { ServiceBase.Run(new ServiceBase[] { AppService.Instance }); } } }
public static void SelfInstall(bool run = false) { ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); //string servicePath = Assembly.GetExecutingAssembly().Location; //string serviceName = Assembly.GetExecutingAssembly().GetName().Name; // //ServiceInstaller installer = new ServiceInstaller(serviceName); //installer.DesiredAccess = ServiceAccessRights.AllAccess; //installer.BinaryPath = servicePath; //installer.DependsOn = new[] { // "MSSQL$SQLEXPRESS" // //"MSSQLSERVER" //}; // //installer.InstallAndStart(); }
public static void Uninstall(string directory = null) { MessageHandler.Print("Trying to uninstall the Servant Agent service..."); try { ManagedInstallerClass.InstallHelper(new[] { "/u", "/LogToConsole=false", directory ?? Assembly.GetExecutingAssembly().Location }); MessageHandler.Print("The service was successfully uninstalled."); } catch (UnauthorizedAccessException) { MessageHandler.Print("Could not uninstall service. Insufficient permissions."); } catch (Exception e) { MessageHandler.Print("There was an error during uninstallation. " + e.Message); } }
private static void InstallService(string[] args) { try { args[0] = Assembly.GetExecutingAssembly().Location; ManagedInstallerClass.InstallHelper(args); } catch (Exception ex) { if (ex.InnerException != null) { ex = ex.InnerException; } Trace.TraceError(ex.Message + "\r\n" + ex.StackTrace); } }
public static void Main(string[] args) { // Check if install or uninstall string[] install_args; if (args.Length > 0 && args[0] == "/uninstall") { install_args = new string[] { "/U", "AsusTCsrv.exe" }; Console.WriteLine("Uninstalling AsusTCsrv ..."); } else { install_args = new string[] { "AsusTCsrv.exe" }; Console.WriteLine("Installing AsusTCsrv ..."); } ManagedInstallerClass.InstallHelper(install_args); }
internal static void Install(bool undo, string[] args) { try { Console.WriteLine(undo ? "uninstalling" : "installing"); if (undo) { ManagedInstallerClass.InstallHelper(new string[] { "/u", System.Reflection.Assembly.GetAssembly(typeof(SvcInstaller)).Location }); } else { ManagedInstallerClass.InstallHelper(new string[] { System.Reflection.Assembly.GetAssembly(typeof(SvcInstaller)).Location }); } } catch (Exception ex) { ClassLogger.Error(ex); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { var arguments = string.Join(" ", args); if (string.IsNullOrEmpty(arguments)) { var servicesToRun = new ServiceBase[] { new Service() }; ServiceBase.Run(servicesToRun); } else if (arguments.StartsWith("--i ")) { try { var connectionString = arguments.Substring("--i ".Length); var connectionStringHelper = new ConnectionStringHelper(); connectionStringHelper.Set(PHmiConstants.PHmiConnectionStringName, connectionString); connectionStringHelper.Protect(); ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location }); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } Console.WriteLine(Res.PressAnyKeyToContinue); Console.ReadKey(); } else if (arguments.StartsWith("--u")) { try { ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location }); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } Console.WriteLine(Res.PressAnyKeyToContinue); Console.ReadKey(); } }
private void UnregisterWindowsService(string path, string serviceName) { try { Log.WriteStart(string.Format("Removing \"{0}\" Windows service", serviceName)); Log.WriteStart(string.Format("Stopping \"{0}\" Windows service", serviceName)); try { Utils.StopService(serviceName); Log.WriteEnd("Stopped Windows service"); } catch (Exception ex) { if (!Utils.IsThreadAbortException(ex)) { Log.WriteError("Windows service stop error", ex); } } try { ManagedInstallerClass.InstallHelper(new[] { "/u", path }); } catch (Exception) { Log.WriteError(string.Format("Unable to remove \"{0}\" Windows service.", serviceName), null); InstallLog.AppendLine(string.Format("- Failed to remove \"{0}\" Windows service", serviceName)); throw; } Log.WriteEnd("Removed Windows service"); InstallLog.AppendLine(string.Format("- Removed \"{0}\" Windows service", serviceName)); } catch (Exception ex) { if (Utils.IsThreadAbortException(ex)) { return; } Log.WriteError("Windows service error", ex); InstallLog.AppendLine(string.Format("- Failed to remove \"{0}\" Windows service", serviceName)); throw; } }
/// <summary> /// Der Haupteinstiegspunkt für die Anwendung. /// </summary> static void Main(string[] args) { if (System.Environment.UserInteractive) { string parameter = string.Concat(args); try { switch (parameter) { case "": var service = new OsramDDStoreSync(); service.StartManual(); Console.WriteLine("Press any key to stop the program"); Console.Read(); service.Stop(); break; case "--install": ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); break; case "--uninstall": ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); break; default: Console.WriteLine("Argument not found"); break; } } catch (Exception e) { Console.WriteLine("(un)install failed", e); } } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new OsramDDStoreSync() }; ServiceBase.Run(ServicesToRun); } }
private static void detach_service(string s_path) { if (s_path != null) { try { if (!s_path.ToLower().EndsWith(".exe")) { throw new ApplicationException("You must send a path, not a name, to detach_service"); } bool exists = false; try { exists = File.Exists(s_path); //I've seen windows throw invalid path exception here (dumb) if (!exists) { Console.Error.WriteLine("ERROR: detach_service could not find '" + s_path + "'"); } } catch (Exception exn) { Console.Error.WriteLine("Could not finish detach_service while checking if '" + s_path + "' exists: " + exn.ToString()); } if (exists) { ManagedInstallerClass.InstallHelper(new string[] { "/u", s_path }); } } catch (Exception exn) { if (exn.ToString().Contains("t exist as an installed service")) { Console.Error.WriteLine("WARNING: skipping detach '" + s_path + "' since not installed as service."); } else if (exn.ToString().Contains("t exist")) { Console.Error.WriteLine("WARNING: skipping detach '" + s_path + "' since does not exist: " + exn.ToString()); } else { Console.Error.WriteLine("Could not finish detach_service: " + exn.ToString()); } } } else { Console.Error.WriteLine("ERROR: detach_service got null string"); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(String [] args) { log4net.Config.XmlConfigurator.Configure(); if (args.Length > 0 && args[0].Trim().ToLower() == "/i") { //Install service try { ManagedInstallerClass.InstallHelper(new[] { "/i", Assembly.GetExecutingAssembly().Location }); } catch (Exception ex) { Logger.Error(ex.ToString()); } } else if (args.Length > 0 && args[0].Trim().ToLower() == "/u") { try { //Uninstall service ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location }); } catch (Exception ex) { Logger.Error(ex.ToString()); } } else { service = new SocketService(); if (args.Length > 0 && args[0].Equals("RunAsService")) { service.RunAsService = true; } else { service.RunAsService = false; Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress); } service.Run(); } }
private static int InstallService() { ScoringReport service = new ScoringReport(); int code = 0; try { // Get current executing path string path = Assembly.GetExecutingAssembly().Location; // Install the service with the Windows Service Control Manager (SCM) ManagedInstallerClass.InstallHelper(new string[] { path }); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.GetType() == typeof(Win32Exception)) { // if Win32Exception, service is already installed Win32Exception wex = (Win32Exception)ex.InnerException; code = wex.ErrorCode; } else { // Unknown error code = -1; } } // Remove file logs to reduce clutter in directory if (File.Exists("InstallUtil.InstallLog")) { File.Delete("InstallUtil.InstallLog"); } if (File.Exists("Scoring Report.InstallLog")) { File.Delete("Scoring Report.InstallLog"); } if (File.Exists("Scoring Report.InstallState")) { File.Delete("Scoring Report.InstallState"); } return(code); }