[英]Programmatically detect Windows cluster configuration?
有谁知道如何以编程方式检测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);
}
}
}
我在这里找到了这段代码并整理了一下。
您要寻找任何特定的语言?
您可能可以为Powershell使用故障转移群集cmdlet (对于Windows Server 2008 R2)。 特别是Get-Cluster
和Get-ClusterNode
我没有确切的答案,但是有很多以“ Cluster”开头的API(例如ClusterOpenEnum和ClusterNodeEnum)和以“ IGetCluster”开头的COM接口看起来很有希望。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.