停止服务组
1 if (string.IsNullOrEmpty(cboServiceGroup.Text)) 2 { 3 MessageBox.Show("请选择要操作的服务组"); 4 return; 5 } 6 // 7 string path = Directory.GetCurrentDirectory() + "/config.ini"; 8 string section = cboServiceGroup.Text; 9 string[] keys; 10 string[] values; 11 INIHelper.GetAllKeyValues(section, out keys, out values, path); 12 // 13 foreach (string value in values) 14 { 15 ServiceController sc = new ServiceController(value); 16 try 17 { 18 ServiceControllerStatus scs = sc.Status; 19 if (scs != ServiceControllerStatus.Stopped) 20 { 21 try 22 { 23 sc.Stop(); 24 } 25 catch (Exception ex) 26 { 27 MessageBox.Show("服务停止失败\n" + ex.ToString()); 28 } 29 } 30 } 31 catch (Exception ex) 32 { 33 MessageBox.Show("不存在服务" + value); 34 } 35 // 36 37 } 38 // 39 MessageBox.Show("服务停止完成"); 40 } |