Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

get a Win32_NetworkAdapterConfiguration object in dotnet

64 views
Skip to first unread message

Dominique Vandensteen

unread,
Apr 11, 2003, 1:22:30 AM4/11/03
to
I'm reading/updating my network conf with .net (system.management)

Dim mc As ManagementClass = New
ManagementClass("Win32_NetworkAdapterConfiguration")
Dim mobj As ManagementObject

I have to use ManagementObject.InvokeMethod to edit my setting.
Is there a way to directly use a Win32_NetworkAdapterConfiguration object?

Dominique


Andy Cheung [MSFT]

unread,
Apr 11, 2003, 3:12:18 PM4/11/03
to
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
 
 
0 new messages