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(GUIDW ithMAC)
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_addr ess(0)), 2) & " " & _
Right$("00" & Hex(AST.adapt.adapter_addr ess(1)), 2) & " " & _
Right$("00" & Hex(AST.adapt.adapter_addr ess(2)), 2) & " " & _
Right$("00" & Hex(AST.adapt.adapter_addr ess(3)), 2) & " " & _
Right$("00" & Hex(AST.adapt.adapter_addr ess(4)), 2) & " " & _
Right$("00" & Hex(AST.adapt.adapter_addr ess(5)), 2)
HeapFree GetProcessHeap(), 0, pASTAT
GetMACAddress2 = tmp
End Function
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(GUIDW
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_addr
Right$("00" & Hex(AST.adapt.adapter_addr
Right$("00" & Hex(AST.adapt.adapter_addr
Right$("00" & Hex(AST.adapt.adapter_addr
Right$("00" & Hex(AST.adapt.adapter_addr
Right$("00" & Hex(AST.adapt.adapter_addr
HeapFree GetProcessHeap(), 0, pASTAT
GetMACAddress2 = tmp
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Plug in a null adapter
ASKER
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
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
ASKER
444553540000
Any more ideas?
Thanks!