代码之家  ›  专栏  ›  技术社区  ›  DougN

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

  •  2
  • DougN  · 技术社区  · 16 年前

    道格

    3 回复  |  直到 14 年前
        1
  •  4
  •   Stuntbeaver    16 年前

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

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

    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 并稍微整理了一下。

        2
  •  1
  •   squillman Johnny Fitz    16 年前

    我没有确切的答案,但有很多以“集群”开头的API(如ClusterOpenEnum和ClusterNodeEnum)和以“IGetCluster”开头的COM接口看起来很有前景。

        3
  •  1
  •   Michael Dunn    16 年前

    failover cluster cmdlets for Powershell (适用于Windows Server 2008 R2)。具体地 Get-Cluster 和 Get-ClusterNode