private void button_flashstate_Click(object sender, EventArgs e) { VMS_statecode vms_result = Service_Manager.get_VMWare_current_state(); String vms_replacetext = (vms_result == VMS_statecode.running) ? "运行中" : (vms_result == VMS_statecode.stop) ? "停止" : "未知"; label_VMWareState.Text = vms_replacetext; HVS_statecode hvs_result = Service_Manager.get_HyperV_current_state(); String hvs_replacetext = (hvs_result == HVS_statecode.running) ? "运行中" : (hvs_result == HVS_statecode.stop) ? "停止" : "未知"; label_HyperVState.Text = hvs_replacetext; }
/// <summary> /// 获取当前VMware服务运行的状态 /// </summary> /// <returns>一个VMS_statecode枚举变量的值,表明当前服务运行的状态</returns> public static VMS_statecode get_VMWare_current_state() { VMS_statecode result = VMS_statecode.unknow; bool ifSomeStatusRunning = false; foreach (string scname in VMWareService_namelist) { ServiceController cur_sc = new ServiceController(scname); if (cur_sc.Status == ServiceControllerStatus.Running) { ifSomeStatusRunning = true; } } if (ifSomeStatusRunning == true) { result = VMS_statecode.running; } else { result = VMS_statecode.stop; } return(result); }