I need to be able to configure the adapter when it is not connected to any
device.(has no link light on it) I am using following
method(WMI-enableStatic) to assign static IPaddress to selected NIC.
It works on XP but returns an error code “ 84 – IP not enabled” on Vista OS.
I have a peer-peer connection with device. The following call works on
Vista as well if device is powered on (I have link light on NIC) . Is there a
way I can assign adapter a static IP address that it can use at later time
when device is up and running ?
Any help/ pointer will be appriciated.
Thanks in advance,
Megha
public static void SetIPAdress(string macID, string IPAddress, string
SubnetMask)
{
ManagementObjectSearcher query = new
ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration
WHERE IPEnabled = 'TRUE'");
ManagementObjectCollection objMOC = query.Get();
int ManagementObjectCount = 0;
foreach (ManagementObject objMO in objMOC)
{
ManagementObjectCount++;
try
{
string macAddr = (string)objMO["MACAddress"];
if (string.Compare(macAddr, macID) == 0)
{
ManagementBaseObject objNewIP = null;
ManagementBaseObject objSetIP = null;
objNewIP = objMO.GetMethodParameters("EnableStatic");
objNewIP["IPAddress"] = new string[] { IPAddress };
objNewIP["SubnetMask"] = new string[] { SubnetMask };
objSetIP = objMO.InvokeMethod("EnableStatic",
objNewIP, null);
}
}
catch (Exception ex)
{
log.InfoFormat("SetIPAdress failed to set IP : " +
ex.Message);
}
}
}
|