使用c#的MSCluster_service [英] MSCluster_service using c#
问题描述
我部署了Windows故障转移群集,其中包含一个或多个群集和服务或与之关联的存储。
I have Windows Failover Cluster deployed with 1 or more clusters and services or storage associated with it.
我是寻找一些如何报告上述内容的C#示例。 我正在尝试报告群集名称,
I am looking for some C# examples of how to report on the above. I am trying to report on the Cluster Name, the
群集上的服务器名称,与群集关联的服务以及与群集关联的存储节点。
Server Names on the cluster, Services associated with the cluster and storage nodes associated with the cluster.
我可以参考哪些有用的示例?
Are there any useful examples that I can refer to?
谢谢。
推荐答案
Hi NMist,
Hi NMist,
> >我可以参考哪些有用的示例?
>>Are there any useful examples that I can refer to?
请参阅以下使用WMI的代码。
Please refer to the following code, which use WMI.
MSCluster_Service的#Caption属性
#Caption property of MSCluster_Service
//Project -> Add reference -> System.Management
//using System.Management;
//create a management scope object
ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\MSCluster");
//create object query
ObjectQuery query = new ObjectQuery("SELECT * FROM MSCluster_Service Where Name=\"Cluster Service\"SystemName=\"W2012SDC\"");
//create object searcher
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
//get a collection of WMI objects
ManagementObjectCollection queryCollection = searcher.Get();
//enumerate the collection.
foreach (ManagementObject m in queryCollection)
{
// access properties of the WMI object
Console.WriteLine("Caption : {0}", m["Caption"]);
}
#WMI查询 - 类实例列表
#WMI query - list of class instances
//Project -> Add reference -> System.Management
//using System.Management;
//set the class name and namespace
string NamespacePath = "\\\\.\\ROOT\\MSCluster";
string ClassName = "MSCluster_Service";
//Create ManagementClass
ManagementClass oClass = new ManagementClass(NamespacePath + ":" + ClassName);
//Get all instances of the class and enumerate them
foreach (ManagementObject oObject in oClass.GetInstances())
{
//access a property of the Management object
Console.WriteLine("Caption : {0}", oObject["Caption"]);
}
致以最诚挚的问候,
张龙
这篇关于使用c#的MSCluster_service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!