public void RestartService() { if (serviceController != null && serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running) { try { serviceController.Stop(); while (serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running || serviceController.Status == System.ServiceProcess.ServiceControllerStatus.StopPending) { Application.DoEvents(); } serviceController.Start(); } catch { } } }
private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e) { using (System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName)) { sc.Start(); } }
void ServiceInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e) { using (System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceInstaller.ServiceName)) { sc.Start(); } }
/// <summary> /// 启动windows服务,只要服务当前状态不是已启动,就启动它,并等待至启动成功,返回true。启动失败,抛出Exception /// </summary> /// <param name="sServiceName"></param> /// <returns></returns> public bool StartWindowService(string sServiceName) { try { if (String.IsNullOrEmpty(sServiceName)) { return(false); } System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(sServiceName); if (sc != null) { if (sc.Status != System.ServiceProcess.ServiceControllerStatus.Running) { sc.Start(); sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); return(true); } return(true); } } catch (Exception e) { Tools.WriteLog(e.ToString()); throw e; } //process not found, return false return(false); }
private void NetQualityTester_AfterInstall_1(object sender, InstallEventArgs e) { using (System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(NetQualityTester.DisplayName)) { sc.Start(); } }
void ServiceInstaller_Committed(object sender, InstallEventArgs e) { // Auto Start the Service Once Installation is Finished. var controller = new System.ServiceProcess.ServiceController(this.serviceInstaller1.ServiceName); controller.Start(); }
private void mi_MailServiceStart_Click(object sender, System.EventArgs e) { serviceController = new System.ServiceProcess.ServiceController("SMTPSVC"); if (serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { try { // Start the service, and wait until its status is "Running". serviceController.Start(); serviceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); // Display the current service status. MessageBox.Show("Mail Service is Started ...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (InvalidOperationException) { MessageBox.Show("Unable to Start Mail Service ...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Mail Service is alrerady Started ...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void llblServiceState_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { Application.DoEvents(); this.Cursor = Cursors.WaitCursor; System.ServiceProcess.ServiceController qsvrc = new System.ServiceProcess.ServiceController("QuickMon 5 Service"); lblServiceState.Text = qsvrc.Status.ToString(); if (llblServiceState.Text == "Start" && qsvrc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { qsvrc.Start(); qsvrc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); } else if (llblServiceState.Text == "Stop" && qsvrc.Status == System.ServiceProcess.ServiceControllerStatus.Running) { qsvrc.Stop(); qsvrc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); } lblServiceState.Text = qsvrc.Status.ToString(); CheckQuickMonServiceInstalled(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Default; }
private bool bStartWindowsService() { if (!bWindowsServiceInstaled()) { bWindowsServiceInstall(); } if (!bWindowsServiceInstaled()) { return(false); } System.ServiceProcess.ServiceController scSiscoMensagem = scReturnSiscoMensagem(); switch (scSiscoMensagem.Status) { case System.ServiceProcess.ServiceControllerStatus.StopPending: case System.ServiceProcess.ServiceControllerStatus.Stopped: try { scSiscoMensagem.Start(); }catch { return(false); } break; } return(this.State == mdlConstantes.SiscoMensagemState.Running); }
/// <summary> /// This event fires after the Install methods of all the installers in the /// Installers property have run. /// </summary> /// <param name="sender"> /// The service installer that is performing the installation. /// </param> /// <param name="e"> /// Data specific to this event. /// </param> void serviceInstaller_AfterInstall(object sender, InstallEventArgs e) { // Create a ServiceInstaller object from the sender object. System.ServiceProcess.ServiceInstaller installer = sender as System.ServiceProcess.ServiceInstaller; // If the ServiceInstaller object was created successfully, attempt to // start the service. if (installer != null) { // Attempt to start the service. try { System.ServiceProcess.ServiceController controller = new System.ServiceProcess.ServiceController(installer.ServiceName); controller.Start(); } // An error occurred when accessing a system API. catch (System.ComponentModel.Win32Exception) { } // The service cannot be started. catch (InvalidOperationException) { } } base.OnAfterInstall(e.SavedState); }
private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e) { //為了要讓程式完成安裝後就直接啟用 System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName); if (sc != null) sc.Start(); }
protected void ExecutionConfirmed(object sender, EventArgs e) { panelMain.Visible = true; confirmPanel.Visible = false; System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("EOBProcessing"); try { sc.Stop(); System.Threading.Thread.Sleep(5000); dbProcedures db = new dbProcedures(); System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("usp_AddOneTimeRunSchedule", new db().SqlConnection); sqlCmd.CommandType = System.Data.CommandType.StoredProcedure; sqlCmd.ExecuteNonQuery(); db.Close(); sc.Start(); lblMessage.Text = "EOB System manual execution started."; } catch (Exception e1) { lblMessage.Text = "Failed to manually start EOB System service." + e1.Message(); } }
private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e) { using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController()) { serviceController.Start(); } }
private bool TryStartService() { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("CallButler Service", Environment.MachineName); try { if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { if (MessageBox.Show(CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_ServiceNotRunning), CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_CallButlerService), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.No) { return(false); } global::Controls.LoadingDialog.ShowDialog(null, CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_StartingService), Properties.Resources.loading, false, 0); // Start the service sc.Start(); sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, TimeSpan.FromSeconds(20)); System.Threading.Thread.Sleep(5); return(true); } } catch (Exception e) { MessageBox.Show(e.Message); } MessageBox.Show(this, CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_ServiceNotFound), "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); }
internal static bool EnsureSqlExpressServiceIsRunning() { System.ServiceProcess.ServiceController cc = new System.ServiceProcess.ServiceController("MSSQL$SQLEXPRESS"); bool result = true; if (cc == null) { throw new Exception("SQLExpress Windows Service not found. Please install SQL Server Express."); } if (cc.Status != System.ServiceProcess.ServiceControllerStatus.Running) { if (MessageBox.Show("SQLExpress is not running. Start?", "SQL Express", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cc.Start(); cc.Refresh(); if (cc.Status != System.ServiceProcess.ServiceControllerStatus.Running) { MessageBox.Show(@"There was a problem starting the SQLExpress Windows Service. Please start it using 'Control Panel\Administration Tools\Services' .", "SQL Express", MessageBoxButtons.OK, MessageBoxIcon.Error); result = false; } } else { result = false; } } return(result); }
/// <summary> /// 启动服务 /// </summary> /// <param name="serviceName"></param> public static void StartService(string serviceName) { if (IsServiceExisted(serviceName)) { System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController(serviceName); if (service.Status != System.ServiceProcess.ServiceControllerStatus.Running && service.Status != System.ServiceProcess.ServiceControllerStatus.StartPending) { service.Start(); for (int i = 0; i < 60; i++) { service.Refresh(); System.Threading.Thread.Sleep(1000); if (service.Status == System.ServiceProcess.ServiceControllerStatus.Running) { break; } if (i == 59) { throw new Exception("Start Service Error:" + serviceName); } } } } }
void ServiceInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e) { using (System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceInstaller.ServiceName)) { sc.Start(); } }
private void serviceInstaller1_Committed(object sender, InstallEventArgs e) { System.ServiceProcess.ServiceController ser = new System.ServiceProcess.ServiceController("AutoSupplyManage_HL"); if (ser.Status != System.ServiceProcess.ServiceControllerStatus.Running | ser.Status != System.ServiceProcess.ServiceControllerStatus.StartPending) { ser.Start(); } }
private void ProjectInstaller_Committed(object sender, InstallEventArgs e) { //インストール直後自動開始 System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(); sc.ServiceName = "log4netRemotingService"; sc.Start(); }
private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e) { //The following code starts the services after it is installed. using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName)) { serviceController.Start(); } }
public static void Start_MySQL_Service() { System.ServiceProcess.ServiceController mysql_Service = new System.ServiceProcess.ServiceController("MySQL"); if (mysql_Service.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { mysql_Service.Start(); } }
void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e) { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("WebApiServer"); if (sc != null) { sc.Start(); } }
private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e) { System.ServiceProcess.ServiceController svr = new System.ServiceProcess.ServiceController(this.serviceInstaller1.ServiceName); if (svr != null) { svr.Start(); } }
protected override void OnAfterInstall(IDictionary savedState) { base.OnAfterInstall(savedState); using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName)) { serviceController.Start(); } }
/// <summary> /// 启动系统服务 /// </summary> /// <param name="sc"></param> public static void StartService(System.ServiceProcess.ServiceController sc) { if ((sc.Status != System.ServiceProcess.ServiceControllerStatus.Running) && (sc.Status != System.ServiceProcess.ServiceControllerStatus.StartPending)) { sc.Start(); sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); } }
void serviceInstaller1_Committed(object sender, InstallEventArgs e) { System.ServiceProcess.ServiceController ser = new System.ServiceProcess.ServiceController("SOSOshopService"); if (ser.Status != System.ServiceProcess.ServiceControllerStatus.Running | ser.Status != System.ServiceProcess.ServiceControllerStatus.StartPending) { ser.Start(); } }
private void ProjectInstaller_Committed(object sender, InstallEventArgs e) { //参数为服务的名字 System.ServiceProcess.ServiceController controller = new System.ServiceProcess.ServiceController("DuPont.Service"); controller.Start(); }
private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e) { // https://stackoverflow.com/a/37992650 using (var sc = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName)) { sc.Start(); } }
private void AfterInstallEventHandler(object sender, InstallEventArgs e) { serviceController1 = new System.ServiceProcess.ServiceController(SERVICE_NAME); serviceController1.Start(); serviceController1.WaitForStatus( System.ServiceProcess.ServiceControllerStatus.Running, TimeSpan.FromMinutes(1)); serviceController1.Close(); }
private void Button_Click_3(object sender, RoutedEventArgs e) { System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("FileSorterService"); //args go here, I have to make these arguments var args = GetArgs(); var serviceArr = ConvertArgsToServiceStringArray(args); serviceController.Start(serviceArr); }
private void AfterInstallEventHandler(object sender, InstallEventArgs e) { serviceController1 = new System.ServiceProcess.ServiceController(SERVICE_NAME); serviceController1.Start(); serviceController1.WaitForStatus( System.ServiceProcess.ServiceControllerStatus.Running, TimeSpan.FromMinutes(1)); serviceController1.Close(); }
protected override void OnAfterInstall(IDictionary savedState) { base.OnAfterInstall(savedState); using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName)) { serviceController.Start(); } }
private void cmdServiceStart_Click(object sender, EventArgs e) { try { System.ServiceProcess.ServiceController dienst = new System.ServiceProcess.ServiceController(ProjectInstaller.ServiceName); dienst.Start(); } catch (Exception) { } }
private void cmdServiceStart_Click(object sender, EventArgs e) { try { System.ServiceProcess.ServiceController dienst = new System.ServiceProcess.ServiceController(ProjectInstaller.ServiceName); dienst.Start(); } catch (Exception) { } }
private void cmdStart_Click(object sender, RoutedEventArgs e) { try { System.ServiceProcess.ServiceController dienst = new System.ServiceProcess.ServiceController(StaticServiceConfig.MyServiceName); dienst.Start(); } catch (Exception) { } }
protected override void OnAfterInstall(IDictionary savedState) { base.OnAfterInstall(savedState); //The following code starts the services after it is installed. using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName)) { serviceController.Start(); } }
protected override void OnAfterInstall(IDictionary savedState) { base.OnAfterInstall(savedState); //The following code starts the services after it is installed. using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName)) { serviceController.Start(); } }
private void cmdStart_Click(object sender, RoutedEventArgs e) { try { System.ServiceProcess.ServiceController dienst = new System.ServiceProcess.ServiceController(StaticServiceConfig.MyServiceName); dienst.Start(); } catch (Exception) { } }
protected override void OnAfterInstall(System.Collections.IDictionary savedState) { base.OnAfterInstall(savedState); try { System.ServiceProcess.ServiceController myController = new System.ServiceProcess.ServiceController("Servicio-eFact-N"); myController.Start(); } catch (Exception ex) { Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(ex); } }
private void StartSqlBrower() { using (System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("SQLBrowser")) { if (sc.Status!=System.ServiceProcess.ServiceControllerStatus.Running) { try { sc.Start(); } catch (Exception) { } } } }
static void Main(string[] args) { Process pro = new Process(); string version = "v2.0.50727"; try { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Environment.GetEnvironmentVariable("windir") + "\\Microsoft.Net\\Framework\\" + version + "\\" + "installutil.exe"; System.Console.WriteLine(psi.FileName); psi.Arguments = " /LogFile= \"" + @args[0] + "\\eFact-N.exe" + "\""; System.Console.WriteLine(psi.Arguments); psi.UseShellExecute = false; psi.RedirectStandardOutput = true; System.Console.WriteLine("Asignar ProcessStartInfo"); pro.StartInfo = psi; System.Console.WriteLine("Ejecutar el Start Process"); pro.Start(); System.Console.WriteLine("Start Process listo"); Console.WriteLine(pro.StandardOutput.ReadToEnd()); pro.WaitForExit(); while (true) { if (pro.HasExited) { System.ServiceProcess.ServiceController myController = new System.ServiceProcess.ServiceController("Servicio-eFact"); myController.Start(); break; } } } catch (Exception ex) { Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(ex); } Console.WriteLine("Presione una tecla para continuar"); Console.ReadLine(); }
private void button1_Click(object sender, EventArgs e) { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(); sc.ServiceName = "MSSQLSERVER"; if (sc == null) { MessageBox.Show("您的机器上没有安装SQL SERVER!", "提示信息"); return; } else if (sc.Status != System.ServiceProcess.ServiceControllerStatus.Running) { sc.Start(); MessageBox.Show("SQL数据库服务启动成功!", "提示信息"); } }
public void HighBackProjectInstaller_Committed(object sender, InstallEventArgs e) { System.ServiceProcess.ServiceController controller = new System.ServiceProcess.ServiceController("HighBack"); controller.Start(); }
private bool isSQLExpressRunning() { bool retVal = true; try { System.ServiceProcess.ServiceController express = new System.ServiceProcess.ServiceController("MSSQL$SQLEXPRESS"); try { if (express.Status != System.ServiceProcess.ServiceControllerStatus.Running) { if (express.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { express.Start(); } UpdateStatus(0, 0, "Waiting for SQL Express Service", "", false); express.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); } if (express.Status != System.ServiceProcess.ServiceControllerStatus.Running) { retVal = false; } } catch (Exception ex) { throw new EMMAException(ExceptionSeverity.Critical, "Cannot start SQL Express service", ex); } } catch (Exception ex) { throw new EMMAException(ExceptionSeverity.Critical, "Problem accessing SQL Express service", ex); } return retVal; }
bool StartEncodingService() { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("Oyster Encoder"); try { if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { sc.Start(); return true; } return false; } catch (Exception ex) { m_log.WriteLog("StartEncodingService: ***ERROR***: " + ex.Message); IsDone = true; return false; } }
bool RestartEncodingService() { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("Oyster Encoder"); if (sc.CanStop) { if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Running) { sc.Stop(); // System.Threading.Thread.Sleep(1000); sc.Start(); return true; } } return false; }
private bool TryStartService() { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("CallButler Service", Environment.MachineName); try { if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { if (MessageBox.Show(CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_ServiceNotRunning), CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_CallButlerService), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.No) { return false; } global::Controls.LoadingDialog.ShowDialog(null, CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_StartingService), Properties.Resources.loading, false, 0); // Start the service sc.Start(); sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, TimeSpan.FromSeconds(20)); System.Threading.Thread.Sleep(5); return true; } } catch(Exception e) { MessageBox.Show(e.Message); } MessageBox.Show(this, CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_ServiceNotFound), "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; }
internal static bool EnsureSqlExpressServiceIsRunning() { System.ServiceProcess.ServiceController cc = new System.ServiceProcess.ServiceController("MSSQL$SQLEXPRESS"); bool result = true; if (cc == null) { throw new Exception("SQLExpress Windows Service not found. Please install SQL Server Express."); } if (cc.Status != System.ServiceProcess.ServiceControllerStatus.Running) { if (MessageBox.Show("SQLExpress is not running. Start?", "SQL Express", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cc.Start(); cc.Refresh(); if (cc.Status != System.ServiceProcess.ServiceControllerStatus.Running) { MessageBox.Show(@"There was a problem starting the SQLExpress Windows Service. Please start it using 'Control Panel\Administration Tools\Services' .", "SQL Express", MessageBoxButtons.OK, MessageBoxIcon.Error); result = false; } } else { result = false; } } return result; }
void ServiceInstaller_Committed(object sender, InstallEventArgs e) { // Auto Start the Service Once Installation is Finished. var controller = new System.ServiceProcess.ServiceController(this.serviceInstaller1.ServiceName); controller.Start(); }
private bool StartSystemService(string service) { if (!SystemServiceExists(service)) return false; try { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(); //sc.MachineName = "localhost"; sc.ServiceName = service; if (sc.Status != System.ServiceProcess.ServiceControllerStatus.Running && sc.Status != System.ServiceProcess.ServiceControllerStatus.StartPending) { sc.Start(); for (int i = 0; i < 60; i++) { SetProgress(0, 60,i ); sc.Refresh(); System.Threading.Thread.Sleep(1000); if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Running) { SetProgress(0, 60, 60); return true; } } SetProgress(0, 60, 60); } return false; } catch (Exception e) { ShowError(e.StackTrace.ToString()); return false; } }