private void InfoServiceForm_Load(object sender, EventArgs e) { gridServiceInfo.Rows.Add("MachineName", _currentService.MachineName); gridServiceInfo.Rows.Add("ServiceName", _currentService.ServiceName); gridServiceInfo.Rows.Add("DisplayName", _currentService.DisplayName); gridServiceInfo.Rows.Add("Status", _currentService.Status.ToString()); gridServiceInfo.Rows.Add("CanShutdown", _currentService.CanShutdown.ToString()); gridServiceInfo.Rows.Add("CanStop", _currentService.CanStop.ToString()); gridServiceInfo.Rows.Add("CanPauseAndContinue", _currentService.CanPauseAndContinue.ToString()); gridServiceInfo.Rows.Add("DependentServices", ServiceControllerArrayToString(_currentService.DependentServices)); gridServiceInfo.Rows.Add("ServicesDependedOn", ServiceControllerArrayToString(_currentService.ServicesDependedOn)); gridServiceInfo.Rows.Add("Site", _currentService.Site != null ? _currentService.Site.ToString() : ""); try { var serviceEngine = new ServiceEngine(_currentService.ServiceName); ServiceInfo si = serviceEngine.GetServiceInfo(); gridServiceInfo.Rows.Add("MarketForDelete", serviceEngine.IsServiceMarkedForDelete.ToString()); gridServiceInfo.Rows.Add("BinaryPathName", si.BinaryPathName); gridServiceInfo.Rows.Add("StartType", si.StartType); gridServiceInfo.Rows.Add("ServiceType", si.ServiceType); gridServiceInfo.Rows.Add("ErrorControl", si.ErrorControl); gridServiceInfo.Rows.Add("LoadOrderGroup", si.LoadOrderGroup); gridServiceInfo.Rows.Add("TagID", si.TagID.ToString()); gridServiceInfo.Rows.Add("StartName", si.StartName); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Удалить выбранный сервис /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonRemove_Click(object sender, EventArgs e) { try { var se = new ServiceEngine(GetSelectedServiceName(), ServiceAccess.Full); se.RemoveService(); Thread.Sleep(1000); RefreshServices(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Create_Click(object sender, EventArgs e) { if (!File.Exists(textBoxFilePath.Text)) { MessageBox.Show("File " + textBoxFilePath.Text + " is not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBoxFilePath.Focus(); return; } ServiceEngine.CreateService(textBoxServiceName.Text, textBoxDisplayName.Text, textBoxFilePath.Text, textBoxCommandLine.Text); if (checkBoxStartAfterCreate.Checked) { new ServiceEngine(textBoxServiceName.Text).StartService(); } }
public List <string> GetAllStoppedServices(string serverName, List <string> servicesFirstPartDisplayNames) { var result = new List <string>(); var allServices = ServiceController.GetServices(serverName); foreach (var serviceController in allServices) { _serviceEngine = new ServiceEngine(serviceController.ServiceName); var serviceInfo = _serviceEngine.GetServiceInfo(); if (serviceInfo.StartType != "Automatically" || serviceController.Status != ServiceControllerStatus.Stopped) { continue; } if (servicesFirstPartDisplayNames.Any(x => serviceController.ServiceName.StartsWith(x))) { result.Add(serviceController.ServiceName); } } return(result); }
private void RefreshServices() { int saveIndex = gridServices.CurrentCellAddress.Y; gridServices.Rows.Clear(); foreach (ServiceController sc in ServiceController.GetServices().OrderBy(x => x.ServiceName)) { var param = new string[7]; param[0] = sc.ServiceName; param[1] = sc.DisplayName; param[4] = sc.Status.ToString(); try { var serEng = new ServiceEngine(sc.ServiceName); ServiceInfo si = serEng.GetServiceInfo(); param[2] = serEng.IsServiceMarkedForDelete.ToString(); param[3] = si.BinaryPathName; param[5] = si.ServiceType; param[6] = si.StartType; } catch (Exception ex) { param[3] = ex.Message; } gridServices.Rows.Add(param); } if (gridServices.Rows.Count > saveIndex) { gridServices.CurrentCell = saveIndex >= 0 ? gridServices.Rows[saveIndex].Cells[0] : gridServices.Rows[0].Cells[0]; } else if (gridServices.Rows.Count > 0) { gridServices.CurrentCell = gridServices.Rows[gridServices.Rows.Count - 1].Cells[0]; } }