gpt4 book ai didi

c# - 从 C# 管理 Windows 集群

转载 作者:太空狗 更新时间:2023-10-29 19:44:35 24 4
gpt4 key购买 nike

我正在尝试在 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);
}
}

最佳答案

看起来您的方法调用中缺少大小写。根据 msdn,您必须使用 TakeOffline

static void TakeOffLine(ManagementObject resourceGroup)
{
ManagementBaseObject outParams =
resourceGroup.InvokeMethod("TakeOffline", null, null);
}

关于c# - 从 C# 管理 Windows 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4867397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com