Skip to content

Commit

Permalink
update function that detect hyper-V service running state
Browse files Browse the repository at this point in the history
  • Loading branch information
RushFTK committed Apr 12, 2019
1 parent 47853fa commit fe4740d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions windows_gui/windows_gui/Main_Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ private void button_flashstate_Click(object sender, EventArgs e)
(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;
}
}
}
26 changes: 24 additions & 2 deletions windows_gui/windows_gui/service_manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace windows_gui
{
class Service_Manager
{

/// <summary>
/// 包含VMWare必要手动开启/关闭与修改手动/自动启动的服务名称
/// </summary>
Expand All @@ -32,9 +33,9 @@ class Service_Manager
};

/// <summary>
/// 获取
/// 获取当前VMware服务运行的状态
/// </summary>
/// <returns></returns>
/// <returns>一个VMS_statecode枚举变量的值,表明当前服务运行的状态</returns>
public static VMS_statecode get_VMWare_current_state()
{
VMS_statecode result = VMS_statecode.unknow;
Expand All @@ -51,5 +52,26 @@ public static VMS_statecode get_VMWare_current_state()
else result = VMS_statecode.stop;
return result;
}

/// <summary>
/// 获取当前HyperV相关服务运行的状态
/// </summary>
/// <returns>一个HVS枚举变量的值,表明当前服务运行的状态</returns>
public static HVS_statecode get_HyperV_current_state()
{
HVS_statecode result = HVS_statecode.unknow;
bool ifSomeStatusRunning = false;
foreach (string scname in HyperVService_namelist)
{
ServiceController cur_sc = new ServiceController(scname);
if (cur_sc.Status == ServiceControllerStatus.Running)
{
ifSomeStatusRunning = true;
}
}
if (ifSomeStatusRunning == true) result = HVS_statecode.running;
else result = HVS_statecode.stop;
return result;
}
}
}

0 comments on commit fe4740d

Please sign in to comment.