I'm collecting all networkadapterconfigurations from the Win32_NetworkAdapterConfiguration
class in C#.
I use this query:
private String strDetailedInterfaces =
@"SELECT *
FROM Win32_NetworkAdapterConfiguration
WHERE DHCPEnabled = 'TRUE'";
However, when selecting the networkadapter that I use to connect to the internet, it says that IPEnabled = false
and when I call the array with IPAddresses
, I get nullpointerexception (meaning that the array = null).
I call the addresses like this:
ManagementObject choosen = (ManagementObject)eInterfacesConfig.Current;
String[] ipAddresses = (String[]) choosen["IPAddress"];
lblIP.Text = ipAddresses[0];
eInterfacesConfig
is a ManagementObjectCollection.Enumerator
and
choosen is the current ManagementObject
out of the enumerator.
I try to change the text of a label (lblIP) to the first Ip address in the array. But this is where the exception throws.
Can someone explain why and perhaps point me into the right direction?