?
Solved

Visual Basic Getting NULL Mac Address?

Posted on 2003-02-28
4
Medium Priority
?
377 Views
Last Modified: 2013-11-25
Hi,

I am having a problem with getting the MAC address of some machines with VB 6.0.  

I have my program attempt to find the MAC address of a users computer using either of these two functions, and it will use which ever one returns a MAC address.

On more than one users machine the MAC address is returned as "0000000000000000".

Is there anything that can commonly cause this?  I know for a fact that the user has a ethernet adapter of modem as the MAC address is sent during a http transaction.

Any ideas?

Thanks!


Private Function getMACAddress() As String
    Dim lpGUIDString As Long
    Dim lBufferLen As Long
    Dim strGUID As String
    Dim vbBuffer() As Byte
    Dim GUIDWithMAC As GUID
    Dim result As Long
    Dim CreateError As Long

    On Error Resume Next
        result = UuidCreateSequential(GUIDWithMAC)
        CreateError = Err.Number
    On Error GoTo 0
    If CreateError = 453 Then
        result = UuidCreate(GUIDWithMAC)
    Else
        Err.Raise CreateError
    End If

    If result = RPC_S_OK Then
        If UuidToString(GUIDWithMAC, lpGUIDString) = RPC_S_OK Then
   
          lBufferLen = lstrlen(lpGUIDString)
          ReDim vbBuffer(lBufferLen - 1) As Byte
   
          Call CopyMemory(vbBuffer(0), ByVal lpGUIDString, lBufferLen)
          RpcStringFree lpGUIDString
          strGUID = StrConv(vbBuffer, vbUnicode)
          getMACAddress = Right(UCase$(strGUID), 12)
        End If
    Else
        getMACAddress = "00"
    End If
End Function

Public Function GetMACAddress2() As String
   Dim tmp As String
   Dim pASTAT As Long
   Dim NCB As NET_CONTROL_BLOCK
   Dim AST As ASTAT
   NCB.ncb_command = NCBRESET
   Call Netbios(NCB)
   NCB.ncb_callname = "*               "
   NCB.ncb_command = NCBASTAT
   NCB.ncb_lana_num = 0
   NCB.ncb_length = Len(AST)
   pASTAT = HeapAlloc(GetProcessHeap(), _
                      HEAP_GENERATE_EXCEPTIONS Or _
                      HEAP_ZERO_MEMORY, _
                      NCB.ncb_length)
   If pASTAT = 0 Then
      Debug.Print "memory allocation failed!"
      Exit Function
   End If
   NCB.ncb_buffer = pASTAT
   Call Netbios(NCB)
   CopyMemory AST, NCB.ncb_buffer, Len(AST)
   tmp = Right$("00" & Hex(AST.adapt.adapter_address(0)), 2) & " " & _
         Right$("00" & Hex(AST.adapt.adapter_address(1)), 2) & " " & _
         Right$("00" & Hex(AST.adapt.adapter_address(2)), 2) & " " & _
         Right$("00" & Hex(AST.adapt.adapter_address(3)), 2) & " " & _
         Right$("00" & Hex(AST.adapt.adapter_address(4)), 2) & " " & _
         Right$("00" & Hex(AST.adapt.adapter_address(5)), 2)
   HeapFree GetProcessHeap(), 0, pASTAT
   GetMACAddress2 = tmp
End Function
0
Comment
Question by:codermar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 300 total points
ID: 8041292
0
 
LVL 1

Author Comment

by:codermar
ID: 8042620
Ok that seems to work to an extent, but I now have this MAC address getting generated:

444553540000

Any more ideas?

Thanks!
0
 

Expert Comment

by:joeski
ID: 8045712
Plug in a null adapter
0
 
LVL 1

Author Comment

by:codermar
ID: 8050354
Still don't have a good viable solution . . .

I need something that will give me the MAC address every time on windows 95/98/ME/2000/NT/XP wether they have a ehternet adapter or a modem . . .

Code or a third party ocx or dll file works fine . . .

Thanks
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question