YZlat
asked on
Using VBScript to get correct MAC Address from computer name
I have a function that gets MAC Address from computer name that runs on Windows XP Embedded but apparently it does not get the correct MAC Address every time. What is wrong with my function. Please help!
Function GetMACAddress(strComputer)
Dim objWMIService, objItem, colItems, mac_addr
On Error Resume Next
'' WMI Connection to the object in the CIM namespace
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'' WMI Query to the Win32_OperatingSystem
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
If objItem.macaddress <> "" Then
mac_addr= Replace(objItem.macaddress,":","")
End If
Next
Set objWMIService = Nothing
GetMACAddress=mac_addr
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What do you consider to be "the right MAC address"? There's likely more than one and your function is only returning one. My first thought is that it doesn't return the same one every time because there's more than one and it occasionally gets them in different sequences.