Link to home
Start Free TrialLog in
Avatar of cdjohn31
cdjohn31

asked on

vb code to query MAC address

Is it possible to find the MAC address of a computer by running a VB script
ASKER CERTIFIED SOLUTION
Avatar of PeteEngineer
PeteEngineer
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try
            Dim nic As NetworkInterface = Nothing
            Dim mac_Address As String = ""

            For Each nic In NetworkInterface.GetAllNetworkInterfaces

                mac_Address = nic.GetPhysicalAddress().ToString
                If mac_Address <> "" Then
                    txtMac_Address.Text = mac_Address
                End If
            Next
               nic = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
Avatar of Joseph Daly
This will query WMI for the mac addresses on the machine. If the computer has multiple network cards or adapters it will return all of the mac addresses.

Save the code as a vbs.
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapter",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_NetworkAdapter instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "MACAddress: " & objItem.MACAddress
Next

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial