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; }
/// <summary> /// 启动windows服务,只要服务当前状态不是已停止,就停止它,并等待至停止成功,返回true。停止失败,抛出Exception /// </summary> /// <param name="sServiceName"></param> /// <returns></returns> public bool StopWindowService(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.Stopped) { sc.Stop(); sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); return(true); } return(true); } } catch (Exception e) { Tools.WriteLog(e.ToString()); throw e; } //process not found, return false return(false); }
private void mi_MailServiceStop_Click(object sender, System.EventArgs e) { serviceController = new System.ServiceProcess.ServiceController("SMTPSVC"); if (serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running) { try { // Start the service, and wait until its status is "Running". serviceController.Stop(); serviceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); // Display the current service status. MessageBox.Show("Mail Service is Stopped successfully...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (InvalidOperationException) { MessageBox.Show("Unable to Stop Mail Service ...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Mail Service is alrerady Stopped ...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
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); }
/// <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); } }
/// <summary> /// 停止系统服务 /// </summary> /// <param name="sc"></param> public static void StopService(System.ServiceProcess.ServiceController sc) { if (sc.CanStop) { sc.Stop(); sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); } }
private void llblFirewallRule_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string regfile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "QuickMon4FirewallRule.reg"); try { if (System.IO.File.Exists(regfile)) { System.IO.File.Delete(regfile); } System.IO.File.WriteAllText(regfile, Properties.Resources.FireWallRule); System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo = new System.Diagnostics.ProcessStartInfo(); p.StartInfo.FileName = "REGEDIT.EXE"; p.StartInfo.Arguments = "/S " + regfile; p.StartInfo.Verb = "runas"; try { p.Start(); p.WaitForExit(); } catch (System.ComponentModel.Win32Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } try { System.ServiceProcess.ServiceController firewallSrvs = new System.ServiceProcess.ServiceController("Windows Firewall"); if (firewallSrvs.Status == System.ServiceProcess.ServiceControllerStatus.Running) { firewallSrvs.Stop(); firewallSrvs.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30)); firewallSrvs.Start(); firewallSrvs.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, new TimeSpan(0, 0, 30)); } llblFirewallRule.Visible = false; } catch { } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void OnProcessExit(object sender, EventArgs e) { try { var service = new System.ServiceProcess.ServiceController("PCManagerService"); service.Stop(); service.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); } catch { } }
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(); }
/// <summary> /// 停止 Windows 服务 /// </summary> /// <param name="serviceName">服务名称。</param> public static void StopService(string serviceName) { if (IsServiceExisted(serviceName)) { System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController(serviceName); if (service.Status != System.ServiceProcess.ServiceControllerStatus.StopPending && service.Status != System.ServiceProcess.ServiceControllerStatus.Stopped) { service.Stop(); } service.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, System.TimeSpan.FromSeconds(60)); } }
public static bool StartService(string serviceName, TimeSpan timeSpan) { if (!ExistService(serviceName)) { return(false); } System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceName); if (sc.Status != System.ServiceProcess.ServiceControllerStatus.Running && sc.Status != System.ServiceProcess.ServiceControllerStatus.StartPending) { sc.Start(); } sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, timeSpan); return(sc.Status == System.ServiceProcess.ServiceControllerStatus.Running); }
private void llblInstallQuickMonService_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string localPath = Environment.CurrentDirectory; string serviceEXE = System.IO.Path.Combine(localPath, "QuickMonService.exe"); quickMonServiceOpenFileDialog.FileName = serviceEXE; quickMonServiceOpenFileDialog.InitialDirectory = localPath; if (quickMonServiceOpenFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { llblInstallQuickMonService.Text = "Installing..."; Application.DoEvents(); System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo = new System.Diagnostics.ProcessStartInfo(); p.StartInfo.FileName = quickMonServiceOpenFileDialog.FileName; p.StartInfo.Arguments = "-install"; p.StartInfo.Verb = "runas"; try { p.Start(); p.WaitForExit(); } catch (System.ComponentModel.Win32Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } try { llblInstallQuickMonService.Text = "Starting..."; Application.DoEvents(); System.ServiceProcess.ServiceController qsvrc = new System.ServiceProcess.ServiceController("QuickMon 5 Service"); if (qsvrc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { qsvrc.Start(); qsvrc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, new TimeSpan(0, 0, 30)); } if (qsvrc.Status == System.ServiceProcess.ServiceControllerStatus.Running) { lblServiceState.Text = qsvrc.Status.ToString(); } else { MessageBox.Show("The installation/start up process of the service may be taking a while. Please wait a few more seconds and refresh this window again", "Service set up", MessageBoxButtons.OK, MessageBoxIcon.Information); } CheckQuickMonServiceInstalled(); } catch { } } }
public void StartService() { if (ServiceName == null) { throw new ServiceException(); } StartTimer(); serviceController = new System.ServiceProcess.ServiceController(ServiceName); 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); Finished = true; // Display the current service status. MessageBox.Show("Mail Service is Started ...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } catch (InvalidOperationException) { Finished = true; MessageBox.Show("Unable to Start Mail Service ...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; this.Close(); return; } } else { Finished = true; MessageBox.Show("Mail Service is alrerady Started ...", "Service Operation Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } this.Close(); }
private void llblLocalServiceRegistered_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string localPath = Environment.CurrentDirectory; string serviceEXE = System.IO.Path.Combine(localPath, "QuickMonService.exe"); quickMonServiceOpenFileDialog.FileName = serviceEXE; quickMonServiceOpenFileDialog.InitialDirectory = localPath; if (quickMonServiceOpenFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo = new System.Diagnostics.ProcessStartInfo(); p.StartInfo.FileName = quickMonServiceOpenFileDialog.FileName; p.StartInfo.Arguments = "-install"; p.StartInfo.Verb = "runas"; try { p.Start(); p.WaitForExit(); } catch (System.ComponentModel.Win32Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } try { System.ServiceProcess.ServiceController qsvrc = new System.ServiceProcess.ServiceController("QuickMon 4 Service"); if (qsvrc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { qsvrc.Start(); qsvrc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); } RefreshServiceStates(); //System.Diagnostics.Process starter = new System.Diagnostics.Process(); //starter.StartInfo = new System.Diagnostics.ProcessStartInfo("sc.exe"); //starter.StartInfo.Arguments = "start \"QuickMon 4 Service\""; //starter.StartInfo.Verb = "runas"; //starter.Start(); //starter.WaitForExit(); //MessageBox.Show("Service started", "Service", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { } } }
public static void StartService(string serviceName, int timeoutMilliseconds) { System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController(serviceName); try { TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds); if (service.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { service.Start(); service.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, timeout); } } catch (Exception ex) { LogBook.Write("Unable to start service Windows audio, please start the service manually. Err:" + ex.Message); } }
//Distributed Transaction Coordinator public bool DistributedTransactionServiceRunning() { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("MSDTC"); if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { sc.Start(); try { sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, TimeSpan.FromSeconds(10)); } catch (System.ServiceProcess.TimeoutException) { return(false); } } return(sc.Status == System.ServiceProcess.ServiceControllerStatus.Running); }
public static bool StopService(string serviceName, TimeSpan timeSpan) { if (!ExistService(serviceName)) { return(false); } System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceName); if (sc.Status != System.ServiceProcess.ServiceControllerStatus.Stopped && sc.Status != System.ServiceProcess.ServiceControllerStatus.StopPending) { sc.Stop(); } sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, timeSpan); var isok = sc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped; sc.Close(); sc.Dispose(); return(isok); }
/// <summary> /// Start the service. /// </summary> /// <param name="name">The name of the service.</param> /// <param name="args">An array of arguments to pass to the service when it starts.</param> /// <param name="timeout">A System.TimeSpan object specifying the /// amount of time to wait for the service to reach the specified status.</param> /// <returns>True if the service is running; else false.</returns> public bool Start(string name, string[] args, TimeSpan timeout) { // Start the process. using (System.ServiceProcess.ServiceController controller = new System.ServiceProcess.ServiceController(name)) { controller.Start(args); controller.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, timeout); if (controller.Status == System.ServiceProcess.ServiceControllerStatus.Running) { return(true); } else { return(false); } } }
/// <summary> /// 停止Windows服务 /// </summary> private void StopService() { try { using (System.ServiceProcess.ServiceController control = new System.ServiceProcess.ServiceController(this.ServiceName)) { if (control.Status != System.ServiceProcess.ServiceControllerStatus.Stopped && control.Status != System.ServiceProcess.ServiceControllerStatus.StopPending) { control.Stop(); } control.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); } } catch { } }
public static int StopService() { Log.Write(TraceEventType.Information, "Stop Service"); if (IISHosted) { WebSite site = GetInstallWebSite(); if (site != null) { WebsiteState state = IISHelper.StopWebSite(site.Name); switch (state) { case WebsiteState.Stopped: return(1); case WebsiteState.Started: return(4); default: return(0); } } return(0); } else { try { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("Workshare Compare Service"); sc.Stop(); sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); return((int)sc.Status); } catch (Exception ex) { Log.Write(TraceEventType.Error, "{0}", ex); return(GetServiceStatus()); } } }
/// <summary> /// Services the stop. /// </summary> /// <param name="WaitForStopping">if set to <c>true</c> [wait for stopping].</param> public static void ServiceStop(bool WaitForStopping) { System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(WUSERVICENAME); if (sc == null) { throw new Exception("service \"" + WUSERVICENAME + "\" not found"); } if ( sc.Status != System.ServiceProcess.ServiceControllerStatus.Stopped && sc.Status != System.ServiceProcess.ServiceControllerStatus.StopPending ) { sc.Stop(); } if (WaitForStopping) { sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 10)); } }
private void llblStartLocalService_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { System.ServiceProcess.ServiceController qsvrc = new System.ServiceProcess.ServiceController("QuickMon 4 Service"); if (qsvrc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) { qsvrc.Start(); qsvrc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, new TimeSpan(0, 0, 30)); qsvrc.Refresh(); if (qsvrc.Status == System.ServiceProcess.ServiceControllerStatus.Running) { MessageBox.Show("Service started", "Service", MessageBoxButtons.OK, MessageBoxIcon.Information); llblStartLocalService.Visible = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Stop the service that depends on the process and its child services /// </summary> /// <param name="process"></param> private void StopDependentService(Process process) { string queryString = "Select * From Win32_Service Where ProcessId=" + SafeGetProcessId(process) + " And State !='Stopped'"; try { using (CimSession cimSession = CimSession.Create(null)) { IEnumerable<CimInstance> serviceList = cimSession.QueryInstances("root/cimv2", "WQL", queryString); foreach (CimInstance oService in serviceList) { string serviceName = oService.CimInstanceProperties["Name"].Value.ToString(); using (var service = new System.ServiceProcess.ServiceController(serviceName)) { //try stopping the service, if cant we are not writing exception try { service.Stop(); // Wait 2 sec for the status to become 'Stopped' service.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 2)); } catch (Win32Exception) { } catch (InvalidOperationException) { } catch (System.ServiceProcess.TimeoutException) { } } } } } catch (CimException ex) { var errorRecord = new ErrorRecord(ex, "GetCimException", ErrorCategory.InvalidOperation, null); WriteError(errorRecord); } }
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; }
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; }
public void CheckFirebirdAndStartFirebird() { try { bool isOK = true; try { string commandText = "select SetupID,SetupName from Setups order by SetupID"; ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); System.Data.DataSet ds = fb.ExecuteDataset(CommonClass.Connection, CommandType.Text, commandText); } catch { isOK = false; } if (isOK == true) { return; } ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ConnectionString"]; string str = settings.ConnectionString; if (!str.Contains(":")) { str = Application.StartupPath + @"\" + str.Substring(str.IndexOf("initial catalog=") + 16); } else { str = str.Substring(str.IndexOf("initial catalog=") + 16); } str = str.Substring(0, str.IndexOf(";")); if (!File.Exists(str)) { MessageBox.Show(string.Format("The BenMAP database file {0} does not exist.", str)); Environment.Exit(0); } try { System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController("FirebirdServerBenMAP-CE"); if (service.Status != System.ServiceProcess.ServiceControllerStatus.Running) { service.Start(); } service.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); } catch { MessageBox.Show("Firebird was not installed successfully. Please install it again."); Process pro = new Process(); pro.StartInfo.UseShellExecute = true; pro.StartInfo.FileName = Application.StartupPath + @"\NecessarySoftware\Firebird-2.1.2_Win32.exe"; pro.Start(); Environment.Exit(0); } try { System.ServiceProcess.ServiceController serviceGuard = new System.ServiceProcess.ServiceController("FirebirdServerBenMAP-CE"); if (serviceGuard.Status != System.ServiceProcess.ServiceControllerStatus.Running) { serviceGuard.Start(); } serviceGuard.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); } catch { try { Process pro = new Process(); pro.StartInfo.UseShellExecute = true; pro.StartInfo.FileName = Application.StartupPath + @"\NecessarySoftware\Firebird-2.1.2_Win32.exe"; pro.Start(); } catch { } } } catch { Environment.Exit(0); } }
static void Main() { String username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; String cname; String serviceName1; String serviceName2; int status = 0; Console.WriteLine("Sea IT POS Freedom Service Reset"); Console.WriteLine("********************************"); Console.WriteLine("Hello, " + username + ", please enter the computer name:"); cname = Console.ReadLine(); String precname = cname.Substring(0, 3).ToUpper(); serviceName1 = "FCCClientSvc"; serviceName2 = "FCCServerSvc"; //Create new service controllers var sr1 = new System.ServiceProcess.ServiceController(serviceName1, cname); var sr2 = new System.ServiceProcess.ServiceController(serviceName2, cname); //display status try { Console.WriteLine(sr1 + " is now " + sr1.Status); Console.WriteLine(sr2 + " is now " + sr2.Status); } catch { switch (precname) { case "SWF": System.Diagnostics.Process.Start("https://swf-dccpfw-rg.nam.int.local/connect/PortalMain"); break; case "SWT": System.Diagnostics.Process.Start("https://swt-dccpfw-rg.nam.int.local/connect/PortalMain"); break; case "BGT": System.Diagnostics.Process.Start("https://bgt-dccpfw-rg.nam.int.local/connect/PortalMain"); break; case "BGW": System.Diagnostics.Process.Start("https://bgw-dccpfw-rg.nam.int.local/connect/PortalMain"); break; case "SWC": System.Diagnostics.Process.Start("https://swc-dccpfw-rg.nam.int.local/connect/PortalMain"); break; case "APC": System.Diagnostics.Process.Start("https://apc-dccpfw-rg.nam.int.local/connect/PortalMain"); break; } Console.WriteLine("Are you connected through VPN?"); Console.WriteLine("Press Enter once connected."); Console.ReadLine(); } //Restart Services try { //FCCClientSvc Console.WriteLine(sr1 + " is now " + sr1.Status); Console.WriteLine(sr2 + " is now " + sr2.Status); if (sr1.Status == System.ServiceProcess.ServiceControllerStatus.Running) { sr1.Stop(); sr1.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); sr1.Start(); sr1.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); status++; } else { sr1.Start(); sr1.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); status++; } //FCCServerSvc if (sr2.Status == System.ServiceProcess.ServiceControllerStatus.Running) { sr2.Stop(); sr2.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); sr2.Start(); sr2.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); status++; } else { sr2.Start(); sr2.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); status++; } if (status != 2) { Console.WriteLine(sr1 + " is now " + sr1.Status); Console.WriteLine(sr2 + " is now " + sr2.Status); Console.ReadLine(); } else { Console.WriteLine("There was an error. Press any key to exit."); Console.ReadLine(); } } catch { Exception e; } }