Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How to get MAC address of your system.

Author: Shahzad

This code sample shows you the way to find out the MAC address of the system. Microsoft.Net provides System.Management namespace to perform this task. With the help of Visual Basic.Net code it's easy.

Import the following namespace.

Imports System.Management

Declare following object variables.

Dim objMOS As ManagementObjectSearcher

Dim objMOC As Management.ManagementObjectCollection

Dim objMO As Management.ManagementObject

Execute the query.

objMOS = New ManagementObjectSearcher("Select * From Win32_NetworkAdapter")

objMOC = objMOS.Get

Get MAC address from the query result.

For Each objMO In objMOC



Dispose object variables.


objMOS = Nothing


objMO = Nothing

Article Comments
My computer does not know the namespace System.Management...

Posted on 5/17/2006 12:40:56 PM by HackMaster

From add references add System.Management.Dll file in your project and then import namespace

Posted on 5/18/2006 7:26:01 AM by Smith

The code what you gave is working but i need to generate only the mac id of the system and it shouldn't be running in a for loop.

How can this be done???With the Same Code

Posted on 1/9/2007 1:55:59 AM by ananth

I can not find system.Management.dll in my system; so, please take a time to send it to me via email address above.
Thanks so much!

Posted on 2/8/2007 4:10:16 AM by bora seng

I did the same in .Net 2003 .But it is giving the following error message "An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll"
at the for each statement .Please tell me how to overcome this error.

Posted on 4/17/2007 2:08:33 AM by Aruna

Thanks for this info :)

Posted on 4/24/2007 1:21:46 PM by atarikg

How to fetch MAC address of a system using ASp.Net

Posted on 1/9/2008 11:47:41 PM by Nagasri

Hi ,
Wat all the columns are there in Win32_NetworkAdapter and why that many rows.

Posted on 1/10/2008 9:16:03 AM by ashish

I have used you code but is is showing error that name space or type specified in the imports system management doesn't contain any public member or cannot be found.

Posted on 2/28/2008 9:48:59 AM by chad

Good Job man

Posted on 4/24/2008 6:18:42 AM by Asjad

this your code is very good, thnk alot

Posted on 4/27/2008 12:03:54 AM by TRAN CAO HUNG

how could i know the mac address of a system

Posted on 5/18/2008 10:52:07 PM by ashish

Want code of VB.NET to get MAC Address of system.

Posted on 7/7/2008 9:48:41 AM by Shankar L Saini


Your code works fine. But my system in LAN connection then how can i get my local MAC Address?

Posted on 12/20/2008 6:49:02 AM by Amjath khan

I am working on location determination for laptop user but it is only for mac address can u guid me more

Posted on 2/26/2010 6:36:35 PM by Naseer

Works Great, you need to include the reference System.Management, but how can I obtain only the Mac Adress of my Ethernet Adapter?
Best Regards

Posted on 3/15/2010 10:52:42 PM by Jesus Zambrano (Ven)

This Code Doesn't Work in Windows 7

Posted on 7/24/2010 5:48:45 AM by zadi

worked perfect on vs 2010...thx

Posted on 8/12/2010 6:40:09 PM by kizp

Hey i am suuper boy

Posted on 11/19/2010 12:39:14 AM by kimmikav

Add Article Comment:
Name :
Email Address :
Comments :
<< How to get processor id (CPU's ID) using Visual Basic.Net

Disclaimer - Privacy
© 2002-2018