kvnsdr
asked on
Win32_NetworkAdapter Array ToString()???
I would like ONE long continuous string of ALL MAC Addresses instead of several individual ones provided by the following method.
ManagementObjectSearcher find = new ManagementObjectSearcher(" SELECT * FROM Win32_NetworkAdapter");
foreach (ManagementObject mo in find.Get())
{
string NicMacAddr = (mo["MACAddress"].ToString ());
}
ManagementObjectSearcher find = new ManagementObjectSearcher("
foreach (ManagementObject mo in find.Get())
{
string NicMacAddr = (mo["MACAddress"].ToString
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is an error you are getting?
ASKER
"Object reference not set to the instance of an object."
NicMacAddr += (NicMacAddr.Length == 0 ? "; " : "") + (mo["MACAddress"].ToString ());
NicMacAddr += (NicMacAddr.Length == 0 ? "; " : "") + (mo["MACAddress"].ToString
Did you include the first line above the loop to define the variable as a string?
ASKER
oh yes, just didn't include in comment.
If the code you provided initially was working, then the changes I showed would give the results you want. But it is possible tha tthe error is from that code...
ASKER
I find it interesting that my code gives the following results.
Notice the duplicate MACs and the blanks that are probably throwing an error with your code.
I only have 2 NICs in the test machine........
I've been using a BREAK; after my code to prevent errors........
MAC Address... D1:FD:04:5E:2D:A4
MAC Address...
MAC Address...
MAC Address... 40:50:44:51:20:20
MAC Address... 23:50:6E:55:20:20
MAC Address...
MAC Address...
MAC Address... 20:02:20:51:42:23
MAC Address... 00:0A:D1:7C:E6:CA
MAC Address... 00:0A:D1:7C:E6:CA
Notice the duplicate MACs and the blanks that are probably throwing an error with your code.
I only have 2 NICs in the test machine........
I've been using a BREAK; after my code to prevent errors........
MAC Address... D1:FD:04:5E:2D:A4
MAC Address...
MAC Address...
MAC Address... 40:50:44:51:20:20
MAC Address... 23:50:6E:55:20:20
MAC Address...
MAC Address...
MAC Address... 20:02:20:51:42:23
MAC Address... 00:0A:D1:7C:E6:CA
MAC Address... 00:0A:D1:7C:E6:CA
ASKER
foreach (ManagementObject mo in find.Get())
{
string[] NicMacAddr = (mo["MACAddress"].ToString
}