我正在尝试在C#中启动/停止基于Windows的群集,下面是我正在使用的代码到目前为止...当我到达下面的TakeOffLine函数时,我从System.Management获得“未找到”异常.ManagementStatus.NotFound。不知道到底发现了什么?如果有(替代)更好的方法,请告诉我。
谢谢!
using System.Management;
class App
{
public static void Main()
{
string clusterName = "clusterHex"; // cluster alias
string custerGroupResource = "clusterHex.internal.com"; // Cluster group name
ConnectionOptions options = new ConnectionOptions();
options.Authentication = System.Management.AuthenticationLevel.PacketPrivacy;
// Connect with the mscluster WMI namespace on the cluster named "MyCluster"
ManagementScope s = new ManagementScope("\\\\" + clusterName +
"\\root\\mscluster", options);
ManagementPath p = new ManagementPath("Mscluster_Clustergroup.Name='" + custerGroupResource + "'");
using (ManagementObject clrg = new ManagementObject(s, p, null))
{
// Take clustergroup off line and read its status property when done
TakeOffLine(clrg);
clrg.Get();
Console.WriteLine(clrg["Status"]);
System.Threading.Thread.Sleep(3000); // Sleep for a while
// Bring back online and get status.
BringOnLine(clrg);
clrg.Get();
Console.WriteLine(clrg["Status"]);
}
}
static void TakeOffLine(ManagementObject resourceGroup)
{
ManagementBaseObject outParams =
resourceGroup.InvokeMethod("Takeoffline", null, null);
}
static void BringOnLine(ManagementObject resourceGroup)
{
ManagementBaseObject outParams =
resourceGroup.InvokeMethod("Takeoffline", null, null);
}
}
答案 0 :(得分:3)
您的方法调用中似乎缺少大小写。您必须根据msdn
使用TakeOffline
static void TakeOffLine(ManagementObject resourceGroup)
{
ManagementBaseObject outParams =
resourceGroup.InvokeMethod("TakeOffline", null, null);
}