A
AMeador
I have searched for the answer to this in many sources, but have not
found a solution that works. I'm wondering if maybe I am missing a
reference, or something. I added a reference to the project by going to
Solution Explorer...Under Project Name...Right Clicked on
Reference...Clicked on Add Reference...Selected the .NET tab...Selected
System.Management...Clicked OK. Here is the code I have tried and the
resulting errors:
using System;
using System.Management;
// I use the same using statements above for each sample below
..
..
// Set up the query.
ManagementObjectSearcher pobjSearcher = new
ManagementObjectSearcher("select
MACAddress from Win32_NetworkAdapter");
// Perform the query and get the addresses.
foreach (ManagementObject pobjObject in pobjSearcher.Get())
// Print the MAC Address to the console.
Console.WriteLine(pobjObject.Item["MACAddress"]);
When I try to compile this, I get the following error:
C:\Development\Work\DoEA Test App\DoEA Test App\frmTest.cs(175):
'System.Management.ManagementObject' does not contain a definition for
'Item'
This is another sample I found. This compiles with no errors, but when
I run it, I get the error posted below the code.
ManagementClass mc = new
ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
if((bool)mo["IPEnabled"] == true)
Console.WriteLine("MAC address\t{0}", mo["MacAddress"].ToString());
mo.Dispose();
}
An unhandled exception of type 'System.Management.ManagementException'
occurred in system.management.dll Additional information: Not found
The line highlighted as the error is:
ManagementObjectCollection moc = mc.GetInstances();
Thanks in advance for any help you can give!
- Andrew
found a solution that works. I'm wondering if maybe I am missing a
reference, or something. I added a reference to the project by going to
Solution Explorer...Under Project Name...Right Clicked on
Reference...Clicked on Add Reference...Selected the .NET tab...Selected
System.Management...Clicked OK. Here is the code I have tried and the
resulting errors:
using System;
using System.Management;
// I use the same using statements above for each sample below
..
..
// Set up the query.
ManagementObjectSearcher pobjSearcher = new
ManagementObjectSearcher("select
MACAddress from Win32_NetworkAdapter");
// Perform the query and get the addresses.
foreach (ManagementObject pobjObject in pobjSearcher.Get())
// Print the MAC Address to the console.
Console.WriteLine(pobjObject.Item["MACAddress"]);
When I try to compile this, I get the following error:
C:\Development\Work\DoEA Test App\DoEA Test App\frmTest.cs(175):
'System.Management.ManagementObject' does not contain a definition for
'Item'
This is another sample I found. This compiles with no errors, but when
I run it, I get the error posted below the code.
ManagementClass mc = new
ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
if((bool)mo["IPEnabled"] == true)
Console.WriteLine("MAC address\t{0}", mo["MacAddress"].ToString());
mo.Dispose();
}
An unhandled exception of type 'System.Management.ManagementException'
occurred in system.management.dll Additional information: Not found
The line highlighted as the error is:
ManagementObjectCollection moc = mc.GetInstances();
Thanks in advance for any help you can give!
- Andrew