2011-02-01 11 views
8

私はC#でWindowsベースのクラスタを起動/停止しようとしていますが、これまで作業していたコードは以下のとおりです...下記のTakeOffLine関数に到達すると、例外は、System.Management.ManagementStatus.NotFoundからです。何が正確に見つからないのか分かりませんか?これを行うための(代替)良い方法がある場合は、私に知らせてください。C#からWindowsクラスタを管理する

ありがとうございます!

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); 
    } 
} 
+1

代わりにPowerShellコマンドレットを使用してのまさかに従ってTakeOffline使用する必要がありますか? –

+4

TakeOfflineとBringOnLineの両方がTakeofflineを呼び出していることに気付きましたか? –

答えて

3

あなたのメソッド呼び出しで大文字と小文字が違います。あなたはmsdn

static void TakeOffLine(ManagementObject resourceGroup) 
{ 
    ManagementBaseObject outParams = 
    resourceGroup.InvokeMethod("TakeOffline", null, null); 
} 
関連する問題