How to get MAC Address in .NET?

  • Thread starter Thread starter shawkee
  • Start date Start date
ManagementObjectSearcher query = null;
ManagementObjectCollection queryCollection = null;

try
{
query = new ManagementObjectSearcher("SELECT * FROM
Win32_NetworkAdapterConfiguration") ;

queryCollection = query.Get();

foreach( ManagementObject mo in queryCollection )
{
if(mo["MacAddress"] != null)
{
Console.WriteLine(mo["MacAddress"].ToString());
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Source);
Console.WriteLine(ex.Message);
}
 
thanks!!!
The ManagementObjectSearcher accept a string looks like a
SQL command. Is there any other
than "Win32_NetworkAdapterConfiguration" we can query?
-----Original Message-----
ManagementObjectSearcher query = null;
ManagementObjectCollection queryCollection = null;

try
{
query = new ManagementObjectSearcher("SELECT * FROM
Win32_NetworkAdapterConfiguration") ;

queryCollection = query.Get();

foreach( ManagementObject mo in queryCollection )
{
if(mo["MacAddress"] != null)
{
Console.WriteLine(mo["MacAddress"].ToString());
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Source);
Console.WriteLine(ex.Message);
}


shawkee said:
Anyone knows how to read the MAC address on the network
card in .NET?


.
 
Win32 hardware classes:
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/computer_system_hardware_classes.asp

All Win32 classes:
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_classes.asp


see also, the newsgroup
microsoft.public.dotnet.framework.wmi


--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m

thanks!!!
The ManagementObjectSearcher accept a string looks like a
SQL command. Is there any other
than "Win32_NetworkAdapterConfiguration" we can query?
-----Original Message-----
ManagementObjectSearcher query = null;
ManagementObjectCollection queryCollection = null;

try
{
query = new ManagementObjectSearcher("SELECT * FROM
Win32_NetworkAdapterConfiguration") ;

queryCollection = query.Get();

foreach( ManagementObject mo in queryCollection )
{
if(mo["MacAddress"] != null)
{
Console.WriteLine(mo["MacAddress"].ToString());
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Source);
Console.WriteLine(ex.Message);
}


shawkee said:
Anyone knows how to read the MAC address on the network
card in .NET?


.
 
Back
Top