"Chuck Haeberle" <Ch***********@ discussions.mic rosoft.com> wrote in message
news:A7******** *************** ***********@mic rosoft.com...
Willy,
I would be very interested in seeing such a sample. What are the WMI
Cluster Classes you mention? I have a similar need - to monitor and
restart
if needed a service on a cluster, and have not had much luck to date
finding
manged objects to allow me to perform this simple task. I could always
issue
shell commands, but thats just ... klugy. :)
Your help would be MOST appreciated!
Chuck Haeberle
Herewith a small sample that illustrates how one can use System.Manageme nt
and WMI to write cluster management application, note that the cluster needs
to run W2K3 for this to work.
using System;
using System.Manageme nt;
class App {
[MTAThread]
public static void Main() {
string clusterName = "MyCluster" ; // cluster alias
string custerGroupReso urce = "FS_Resourc e1"; // Cluster group name
ConnectionOptio ns options = new ConnectionOptio ns();
options.Usernam e = "ClusterAdm in"; //could be in domain\user format
options.Passwor d = "HisPasswor d";
// Connect with the mscluster WMI namespace on the cluster named "MyCluster"
ManagementScope s = new ManagementScope ("\\\\" + clusterName +
"\\root\\msclus ter", options);
ManagementPath p = new ManagementPath( "Mscluster_Clus tergroup.Name=' " +
custerGroupReso urce +"'");
using(Managemen tObject clrg = new ManagementObjec t (s, p, null ))
{
// Take clustergroup off line and read its status property when done
TakeOffLine(clr g);
clrg.Get();
Console.WriteLi ne(clrg["Status"]);
System.Threadin g.Thread.Sleep( 3000); // Sleep for a while
// Bring back online and get status.
BringOnLine(clr g);
clrg.Get();
Console.WriteLi ne(clrg["Status"]);
}
}
static voidTakeOffLine (ManagementObje ct resourceGroup)
{
ManagementBaseO bject outParams =
resourceGroup.I nvokeMethod("Ta keoffline", null, null);
}
static void BringOnLine(Man agementObject resourceGroup)
{
ManagementBaseO bject outParams =
resourceGroup.I nvokeMethod("Ta keoffline", null, null);
}
}
Check the MSDN documentation for all other WMI mscluster namespace classes,
and write some small programs to exercize the features offered by the
individual classes.
If in doubt about some property or feature, load wbemtest.exe and connect to
the cluster namespace. Wbemtest allows you to get/change the properties of
cluster resources and execute the methods exposed by the mscluster classes.
Willy.