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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim nic As NetworkInterface = Nothing
Dim mac_Address As String = ""
For Each nic In NetworkInterface.GetAllNet
mac_Address = nic.GetPhysicalAddress().T
If mac_Address <> "" Then
txtMac_Address.Text = mac_Address
End If
Next
nic = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try