gpt4 book ai didi

windows - 以编程方式检测 Windows 群集配置?

转载 作者:可可西里 更新时间:2023-11-01 09:50:05 37 4
gpt4 key购买 nike

有谁知道如何以编程方式检测 Windows 服务器是集群的一部分吗?

再者,能否检测出服务器是主动节点还是被动节点?

[编辑] 并从 Win32 中检测到它?可能是注册表设置?

感谢您的任何见解。

道格

最佳答案

您可以使用 WMI 来查找信息。这应该适用于 XP/Win32 等。

这里有一些关于使用 VBScript 完成这项工作的重要信息: http://www.activexperts.com/activmonitor/windowsmanagement/scripts/networking/clustering/

下面是一些也使用 WMI 的 C#/.Net 代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Management;

namespace SandboxConsole
{
public class ClusterAdmin
{
[MTAThread]
public static void Main()
{
string clusterName = "MyCluster"; // cluster alias
string custerGroupResource = "FS_Resource1"; // Cluster group name
ConnectionOptions options = new ConnectionOptions();
options.Username = "ClusterAdmin"; //could be in domain\user format
options.Password = "HisPassword";

// 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);
}
}
}

我找到了这段代码 here并整理了一下。

关于windows - 以编程方式检测 Windows 群集配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1730133/

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