Link to home
Start Free TrialLog in
Avatar of codermar
codermar

asked on

Visual Basic Getting NULL Mac Address?

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
ASKER CERTIFIED SOLUTION
Avatar of EDDYKT
EDDYKT
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of codermar
codermar

ASKER

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

444553540000

Any more ideas?

Thanks!
Plug in a null adapter
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