Results 1 to 7 of 7

Thread: Obtaining MAC Address

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    67

    Obtaining MAC Address

    Hi. I am using VB6 and need to obtain the MAC address of the network card in my computer. The end result I would like is simply a label which displays the MAC address of the network card.

    I have looked on the net already and found lots of very complicated code which I think maybe not what I need anyway.

    Any help is appreciated

  2. #2
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Re: Obtaining MAC Address

    This would work. This code uses WMI calls to get the computer information. This section of code will get the mac address of the network card that is in use that the time.

    Code:
    Public Sub GetWMIAdapter()
    Dim oAdapters As Object
    Dim oAdapter As Object
    
    On Error Resume Next
    
    Set oAdapters = GetObject("winmgmts:").ExecQuery( _
        "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
        
    For Each oAdapter In oAdapters
        With oAdapter
             Label1.Caption "MAC:" & vbTab & vbTab & .MACAddress
        End With
    Next
    End Sub
    If my post was helpful please rate it

  3. #3
    New Member
    Join Date
    Apr 2005
    Posts
    2

    Re: Obtaining MAC Address

    Hi Wiccaan

    Ive done this sujestion:

    Code:
    Private Sub Command1_Click()
    Call GetWMIAdapter
    End Sub
    
    Public Sub GetWMIAdapter()
    Dim oAdapters As Object
    Dim oAdapter As Object
    
    On Error Resume Next
    
    Set oAdapters = GetObject("winmgmts:").ExecQuery( _
        "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
        
    For Each oAdapter In oAdapters
        With oAdapter
             Label1.Caption "MAC:" & vbTab & vbTab & .MACAddress
        End With
    Next
    End Sub
    I get a compile error which says invalid use of property and highlights .caption

    Im a noob to all this VB sorry if its a silly question

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    67

    Re: Obtaining MAC Address

    I think you need to change the line:

    Label1.caption "MAC ...
    to
    Label1.caption = "MAC ...

  5. #5
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Re: Obtaining MAC Address

    As TheBoy pointed out... it was missing the '=' that was my fault. Sorry about that, but it should work.
    If my post was helpful please rate it

  6. #6
    New Member
    Join Date
    Apr 2005
    Posts
    2

    Re: Obtaining MAC Address

    Cheers guys, silly me, im a noob

    Heres one for you wiccaan,

    I need to write some code that can do a tracert www.yahoo.com (any url) and save the first Hop ip address.

    Can this be done?

    cheers

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Obtaining MAC Address

    You could shellexecute tracert.exe passing the correct parameters and output to a textfile. Then read the file into your program.
    Code:
    tracert -d -h 1 > C:\OneHop.txt www.yahoo.com
    
    Tracing route to www.yahoo.akadns.net [66.94.230.32]
    
    over a maximum of 1 hops:
    
    
    
      1    <1 ms    <1 ms    <1 ms  192.168.1.1 
    
    
    
    Trace complete.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width