• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1807
  • Last Modified:

retrieve MAC address from ethernet card using VB 6

Is there a way to retrieve a MAC address on a PC using VB 6? A sample of code would be great.

Thanks in advance.
0
samic400
Asked:
samic400
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
imarshadCommented:
One simple solution is to use the following from a  shell
"IPCONFIG/ALL > C:\MAC_ADDRESS.TXT"
This will write all the info in the text file then you can read and parse the text file and get the physical address.

Direct from source code
http://vbnet.mvps.org/index.html?code/network/macaddress.htm
http://www.thescarms.com/vbasic/MACaddress.aspx
0
 
VKCommented:

Private Sub Form_Load()
    Dim MACs() As String
    Dim i As Long
    
    MACs = MACAddressWMI
    For i = 0 To UBound(MACs)
        If Len(MACs(i)) > 0 Then List1.AddItem MACs(i)
    Next i
End Sub
 
Public Function MACAddressWMI() As String()
    Dim WMIobj As Object
    Dim MACobj As Object
    Dim s() As String
    On Error Goto ErrOut
    
    ReDim s(0)
    Set WMIobj = GetObject("winmgmts:").ExecQuery("SELECT MACAddress FROM Win32_NetworkAdapter " & _
              "WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))")
    
    For Each MACobj In WMIobj
        ReDim s(UBound(s) + 1)
        s(UBound(s)) = MACobj.MACAddress
    Next MACobj
    
    MACAddressWMI = s
    Exit Function
ErrOut:
    MsgBox "Error! WMI not found!"
End Function

Open in new window

0
 
samic400Author Commented:
VK, this would retrieve a MAC address for a wireless router card as well?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
VKCommented:
It doesn't make a difference if the network atdapter is wireless or not.
It has to be a built in adapter.
0
 
samic400Author Commented:
The problem with this code is when I run this from my laptop, it come up with an error "WMI Not Found" and it cannot find any MAC address at all. When I run it from my desktop, I get an entry in the listbox.
0
 
VKCommented:
0
 
team2005Commented:
0
 
samic400Author Commented:
Team2005, this worked great, VK I still couldn't get the MAC address to appear in any of the examples. Thanks for the help folks!
0
 
team2005Commented:
Hi!

Thanks for the points :)

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now