Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Thursday, January 27, 2011 2:49 PM
Private Shared Function GetMacAddress() As String
Dim qstring As String = "SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = true"
For Each mo As System.Management.ManagementObject In New
System.Management.ManagementObjectSearcher(qstring).Get()
Dim macaddress As String = mo("MacAddress")
If Not macaddress Is Nothing Then
Return macaddress
End If
Next
Return ""
End Function
i got those code somewhere, but i cant use it, i mean i want the result of mac address in textbox.
so i have one form with one textbox and one button, when i click this button, the MacAddress will show up in the textbox. how can i do that?
thanks
Thursday, January 27, 2011 4:48 PM ✅Answered | 4 votes
There's managed way of getting MAC address of a specific network adapter by means of System.Net.NetworkInformation.NetworkInterface.
Imports System.Net.NetworkInformation
** Function getMacAddress()
Dim nics() As NetworkInterface = _
NetworkInterface.GetAllNetworkInterfaces
Return nics(0).GetPhysicalAddress.ToString
End Function**
Just call getMacAddress to get first network adapter's mac address which is usually the active one. Or you can loop through "nics" array to get other network adapters, as well.
HTH.
Saygılarımla, Onur Güzel
[Yazgeliştir Forumları'ndayım.
](http://www.yazgelistir.com/Forumlar/UyeBilgileri.aspx?UyeId=1000107000)Microsoft Haber Grupları Profilim (VB.NET)
Thursday, January 27, 2011 3:09 PM | 1 vote
TextBox1.Text = GetMacAddress() should work.
--
Mike
Saturday, May 23, 2015 6:17 PM
It´s work for me, now this code will help me very much for my proyect!!!!!!