Created
August 10, 2012 02:42
-
-
Save dck-jp/3310512 to your computer and use it in GitHub Desktop.
Get MAC Address @ VBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Function GetMacAddress() | |
Dim objNetwork As Object | |
Dim strNetworkSql As String | |
Dim strMacAdr As String | |
strNetworkSql = "SELECT * FROM Win32_NetworkAdapter WHERE MACAddress IS NOT NULL" | |
For Each objNetwork In GetObject("winmgmts:").ExecQuery(strNetworkSql) | |
strMacAdr = objNetwork.MACAddress | |
If strMacAdr <> "" Then Exit For | |
Next | |
GetMacAddress = strMacAdr | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's just picking the first MAC address it finds - today you'll have at least some virtual network adapters (Windows "prefab" VPN and other tunneling, e.g. ISATAP, Teredo, 6to4), so it's very optimistic that your actual phyical adapter is retrieved as first. Though that might be the case on most computers, you should not rely on that when deploying software, i.e. running on arbitrary computers.