开发者

Managing a windows cluster from C#

I am trying to start/stop a windows based cluster in C#, below is the code I am working with so far...when I get to TakeOffLine function below I get a "Not Found" exception from, System.Management.ManagementStatus.NotFound. Not sure what is exactly not being found? If there is a (alternate) better way of doing this please let me know.

Thanks!

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 resourc开发者_开发知识库eGroup)
    {
        ManagementBaseObject outParams =
        resourceGroup.InvokeMethod("Takeoffline", null, null);
    }
}


Looks like you're missing case in your method call. You have to use TakeOffline according to msdn

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜