tags:

views:

256

answers:

2

Hi. I have read this article about using WMI to change the settings of NICs ( Article)

But I can't figure out how to change the settings of a single NIC (based on MACaddress, ID or whatever) instead of all NICs !?

Anyone ?

A: 

Quick 'n dirty:

foreach(ManagementObject objMO in objMOC) 
{ 
    if(!(bool)objMO["ipEnabled"]) 
        continue;

    if(!string.Equals(objMO["MACAddress"], "00:ff:xx:xx:xx:xx"))
        continue;

    // change settings

    break;
}
dtb
Thanks mate ! I might be back with another related question sometime soon ;)
Oppermann
A: 

Hi !

One big problem with WMI is usually, that you do not find the information easyly, if an object/property is read-only or updatable.

But the genral way to this - for your loop above - would be this:

objMO["PropertyName"] = "newValue";
//But may be the following (I do it rarely):
//objMO["PropertyName"].Value = "newValue";
objMO.Put();    //That it!

Naturally, use the right datatype.

Try it, I hope, it helps!

br--mabra

mabra