Generally, to get a ManagmentObject directly, you first use need
to know the instance path of the WMI instance you want to get. And
then you'd call one of the ManagementObject class constructor. Sometimes, you
can get ManagementObject objects directly through instance enumeration or
WMI object queries. e.g.
//This snippet sets a static IP address and subnet mask on a machine.
// Enumerate all network adapters on a machine
SelectQuery query = new
SelectQuery("Win32_NetworkAdapterConfiguration",
"IPEnabled='TRUE'");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(query);
string[] ipAddress =
{"179.31.124.12"};
string[] subnetMask =
{"255.255.248.0"};
foreach(ManagementObject networkAdapter in
searcher.Get())
{
// Set new IP
address
ManagementBaseObject inParams =
networkAdapter.GetMethodParameters("EnableStatic");
inParams["IPAddress"]
= ipAddress;
inParams["SubnetMask"] =
subnetMask;
ManagementBaseObject outParams =
networkAdapter.InvokeMethod("EnableStatic", inParams,
null);
Console.WriteLine("Executing
EnableStatic method returns {0}", outParams["ReturnValue"]);
}
--
Andy Cheung
Microsoft WMI Test Engineer
This posting is
provided "As Is" with no warranties, and confers no rights.
Use of included
script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm