Results 1 to 7 of 7

Thread: [VB6] GetAdaptersInfo Example

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    [VB6] GetAdaptersInfo Example

    See GetAdaptersInfo function for the details.

    This sample program makes some basic use of the API call and the results it returns to report on network adapters in your system. If you need more information you can easily expand upon it to extract multiple IP addresses where they exist, etc.

    There are some limitations when using early versions of Windows, so see the MSDN link above if you need support for Windows XP or earlier.

    Sample output, Adapter 0 is not connected to a network:

    Code:
    2 adapter(s) found.
    
    Adapter 0:
    	Description = Realtek RTL8191SU Wireless LAN 802.11n USB 2.0 Network Adapter
    	AdapterIndex = 23
    	Name = {E9D4C1E7-8714-4545-A74B-A2FF60453A00}
    	Type = 71
    	Address = 00-12-71-BA-C4-34
    	IP = 0.0.0.0
    	GatewayIP = 0.0.0.0
    
    Adapter 1:
    	Description = Realtek PCIe GBE Family Controller
    	AdapterIndex = 11
    	Name = {F4747718-7BF6-4369-97C0-76A31249F698}
    	Type = 6
    	Address = 00-14-71-21-A3-11
    	IP = 192.168.0.100
    	GatewayIP = 192.168.0.1
    This works even when WMI is not installed, the WMI Service is stopped, or WMI has "gone bye bye" and started returning bogus results.

    Note that Address varies by adapter type. For Ethernet, WiFi, and similar network media adapters this is the MAC Address.


    This might look like a lot of code, but much of it consists of structure definitions (UDTs). For specific purposes you can trim out things you do not need which can reduce it further.
    Attached Files Attached Files
    Last edited by dilettante; Feb 23rd, 2016 at 12:08 PM. Reason: reposted attachment - hope this got the bugs

  2. #2
    Hyperactive Member
    Join Date
    Sep 2014
    Posts
    341

    Re: [VB6] GetAdaptersInfo Example

    <Invalid Procedure Call> when testing in IDE, installed on my WIN7 OS.

    Name:  1.jpg
Views: 2000
Size:  16.4 KB

    Hi Dilettante

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] GetAdaptersInfo Example

    Well ok, then try:

    Code:
    Private Function HexBytes(ByRef Bytes() As Byte, ByVal Length As Long) As String
        Const HEX_CHARS As String = "0123456789ABCDEF"
        Dim I As Long
    
        If Length Then
            HexBytes = String$(Length * 3 - 1, "-")
            For I = 0 To Length - 1
                Mid$(HexBytes, 1 + I * 3, 1) = Mid$(HEX_CHARS, 1 + Bytes(I) \ &H10, 1)
                Mid$(HexBytes, 2 + I * 3, 1) = Mid$(HEX_CHARS, 1 + Bytes(I) And &HF, 1)
            Next
        End If
    End Function
    It sounds as if you had one with no Address value, so Length was passed a 0.

  4. #4
    Hyperactive Member
    Join Date
    Sep 2014
    Posts
    341

    Re: [VB6] GetAdaptersInfo Example

    It doesn't work. Please check the screenshot below:

    Name:  QQ??20160223141955.jpg
Views: 2141
Size:  39.6 KB

    I didn't change your code. I simply downloaded your demo and ran in the IDE.

  5. #5
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [VB6] GetAdaptersInfo Example

    Code:
    Mid$(HexBytes, 2 + I * 3, 1) = Mid$(HEX_CHARS, 1 + (Bytes(I) And &HF), 1)

  6. #6
    Hyperactive Member
    Join Date
    Sep 2014
    Posts
    341

    Re: [VB6] GetAdaptersInfo Example

    Mid$(HexBytes, 2 + I * 3, 1) = Mid$(HEX_CHARS, 1 + (Bytes(I) And &HF), 1)

    Wow this works. It seems that And Operator should have had higher precedence? It works differently on different machines?

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] GetAdaptersInfo Example

    That was the bug. No idea why it seemed to work fine for me earlier... it probably was giving bad results.

    The (MAC, etc.) Address field support was added quickly. Too quickly, clearly.

    I'll repost the archive above. Sorry for the grief, and thanks for helping find this.

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