"Billy Bob" <who@microsoft.comwrote in message
news:eQv$1CcXHHA.1296@TK2MSFTNGP02.phx.gbl...
Hello
I've got three network adapter on my machine, and I'm looking to use WMI
to set the IP address of each apapter but I need some help. My network
adapters are Intel (R) Pro/100 VE, PRO/1000 CT, PRO/1000 MT and I want to
set the first to an IP of 192.168.100.100, the second NIC to
192.168.100.200, and the third to 192.168.100.300. The following code
runs without errors, but my IP addresses never change. Any idea's ?
Yes. Visual Studio will create a wrapper type for the management class,
making this a whole lot easier.
With your project open in Visual Studio, open the "Server Explorer", Expand
Servers/[Your Computer Name]/Management Classes, right-click on "Network
Adapter Settings" and choose "Generate Managed Class". This will create a
type called ROOT.CIMV2.Win32_NetworkAdapterConfiguration in your project.
Then just use that type like this:
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.Diagnostics;
using csTestLib.ROOT.CIMV2;
namespace Test
{
public class Program
{
public static void Main(string[] args)
{
try
{
foreach (NetworkAdapterConfiguration a in
NetworkAdapterConfiguration.GetInstances())
{
Console.WriteLine("In Loop - " + a.Description);
if (!a.IPEnabled)
continue;
if (a.Description == "Microsoft Loopback Adapter")
{
a.EnableStatic(new string[] { "10.39.0.10" },
new string[] { "255.255.0.0" });
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.WriteLine("Hit any key to exit");
Console.ReadKey();
}
}
}
David