Rob van der Woude's Scripting Pages

VBScript Scripting Techniques > Network > MAC Address(es)

Retrieve Your Computer's MAC Address(es)

 

Win32_NetworkAdapter
VBScript Code:
intCount = 0
strMAC   = ""
' We're interested in MAC addresses of physical adapters only
strQuery = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID > ''"

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If InStr( strMAC, objItem.MACAddress ) = 0 Then
        strMAC   = strMAC & "," & objItem.MACAddress
        intCount = intCount + 1
    End If
Next

' Remove leading comma
If intCount > 0 Then strMAC = Mid( strMAC, 2 )

Select Case intCount
    Case 0
        WScript.Echo "No MAC Addresses were found"
    Case 1
        WScript.Echo "MAC Address: " & strMAC
    Case Else
        WScript.Echo "MAC Addresses: " & strMAC
End Select
Requirements:
Windows version: Windows NT 4 SP4, 2000, XP, Server 2003, or Vista
Network: TCP/IP
Client software: WMI CORE 1.5 for Windows NT 4
Script Engine: any
Summarized: Works in Windows NT 4 SP4 (with WMI CORE 1.5), Windows 2000 or later.
Doesn't work in Windows 95, 98 or ME.
 
[Back to the top of this page]

page last uploaded: 2016-09-19, 14:58