How do I get MAC address? (1 Viewer)

marlan

Registered User.
Local time
Today, 18:57
Joined
Jan 19, 2010
Messages
409
Hi all of you,

I would like my acc 2003 software to get the users MAC address. I've found this on this forum, and other basically similar answers at other sites. They all return me the same answer: 0-0-0-0-0-0. From reading on I understand that because I have 2 MAC cards, one of them is wireless, I actually get the address of an adaptor, not of the card.

can anyone please help me on getting passed the adaptor, and receiving this unique ID number?
 

penguino29

Registered User.
Local time
Today, 16:57
Joined
Dec 23, 2010
Messages
52
Hi Marlan,

The following code works in Access 2010. Maybe you can give it a try.


Code:
Sub GetMACAddress()
' get a list of enabled adaptor names and MAC addresses
' from msdn.microsoft.com/en-us/library/windows/desktop/aa394217(v=vs.85).aspx

Dim objVMI As Object
Dim vAdptr As Variant
Dim objAdptr As Object

Set objVMI = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set vAdptr = objVMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")


For Each objAdptr In vAdptr
    Debug.Print objAdptr.Caption & " " & objAdptr.MACAddress
Next objAdptr

End Sub

The above will print out list of adaptor's name (objAdptr.Caption) and its associated MAC address (objAdptr.MACAddress) in the immediate window.

I have yet to figure out how to get the IP addresses as they appear to be in an array.
 

jose.natali

New member
Local time
Today, 08:57
Joined
Aug 10, 2013
Messages
2
This work for me: (Access 2007)

Code:
Public sub NIC_Info As String

    Dim myWMI As Object, myObj As Object, Itm

    Set myWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set myObj = myWMI.ExecQuery("SELECT * FROM " & _
                     "Win32_NetworkAdapterConfiguration " & _
                     "WHERE IPEnabled = True")
    For Each Itm In myObj
        debug.print Itm.IPAddress(0)
        debug.print Itm.MACAddress
        Exit for
    Next
End sub
 

marlan

Registered User.
Local time
Today, 18:57
Joined
Jan 19, 2010
Messages
409
Hi, I haven't used it at the time (decided not to use Mac IDs), but have now tested jose.natali's method, and it seems to give a MAC ID. I got the same ID for my Cable and wireless networks, but it wasn't 0. Please let us know if it does the job for you.
 

spikepl

Eledittingent Beliped
Local time
Today, 17:57
Joined
Nov 3, 2010
Messages
6,142
@marlan

you are wasting your time on a spammer
 

mester

Member
Local time
Today, 16:57
Joined
Apr 2, 2020
Messages
63
This work for me: (Access 2007)

Code:
Public sub NIC_Info As String

    Dim myWMI As Object, myObj As Object, Itm

    Set myWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set myObj = myWMI.ExecQuery("SELECT * FROM " & _
                     "Win32_NetworkAdapterConfiguration " & _
                     "WHERE IPEnabled = True")
    For Each Itm In myObj
        debug.print Itm.IPAddress(0)
        debug.print Itm.MACAddress
        Exit for
    Next
End sub
hi how are you? please, it doesn't work for me, can you explain where should i put this code?
i mean , should i use it in a buton or where exactly?
 

Micron

AWF VIP
Local time
Today, 11:57
Joined
Oct 20, 2018
Messages
3,478
#1 - the thread is 7 years old and I doubt anyone you're addressing will be around to answer your question
#2 - when you have already posted a question on this forum somewhere, please don't ask the same question in another part of the forum unless you provide links between your posts. That assumes you have a legitimate reason for posting the same question 2x in different places. This is also you, yes?
 

mester

Member
Local time
Today, 16:57
Joined
Apr 2, 2020
Messages
63
#1 - the thread is 7 years old and I doubt anyone you're addressing will be around to answer your question
#2 - when you have already posted a question on this forum somewhere, please don't ask the same question in another part of the forum unless you provide links between your posts. That assumes you have a legitimate reason for posting the same question 2x in different places. This is also you, yes?
i am so sorry, i am new here so i don't know the rules yet , sorry again
 

Micron

AWF VIP
Local time
Today, 11:57
Joined
Oct 20, 2018
Messages
3,478
No problem.
Did you not have success with your other post? You seemed thankful for the suggestions that were offered.
 

isladogs

MVP / VIP
Local time
Today, 16:57
Joined
Jan 14, 2017
Messages
18,227
Did you actually try the function I posted in the other thread? If so, did it work for you? If not, what happened?
 

mester

Member
Local time
Today, 16:57
Joined
Apr 2, 2020
Messages
63
Yes , thanks, your suggestions helped me a lot.
The code is working, but when i am not connected to the internet, i can't get the Mac Adress, is there any solution plz.
My second Question is, the serial number of the computer , is it unique and could we use it to protect our applications from stelling. I use this function to get my serial numebr :
SerialNumber= CreatObject("Scripting.FileSystemObject").GetDrive("c:\").SerialNumber.

It's work for me but instead of getting the same serial number back the laptop or when i use cmd.exe ,i get another number.
 

Attachments

  • IMG20200512072504.jpg
    IMG20200512072504.jpg
    1.1 MB · Views: 135
  • IMG20200512072428.jpg
    IMG20200512072428.jpg
    2.7 MB · Views: 152
  • IMG20200512072504.jpg
    IMG20200512072504.jpg
    1.1 MB · Views: 124
  • IMG20200512063252.jpg
    IMG20200512063252.jpg
    2.3 MB · Views: 132
Last edited:

isladogs

MVP / VIP
Local time
Today, 16:57
Joined
Jan 14, 2017
Messages
18,227
@mester
Suggest you create your own thread and explain exactly what you are trying to do.
If it helps, I have functions for finding the hard drive, motherboard and CPU numbers and use each of these in conjunction with other information to secure some of my apps using an activation process so they can only be used on a registered computer(s)
 

mester

Member
Local time
Today, 16:57
Joined
Apr 2, 2020
Messages
63
@mester
Suggest you create your own thread and explain exactly what you are trying to do.
If it helps, I have functions for finding the hard drive, motherboard and CPU numbers and use each of these in conjunction with other information to secure some of my apps using an activation process so they can only be used on a registered computer(s)
Thanks for your help, Gasman proposition did well with me, thanks again
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:57
Joined
May 7, 2009
Messages
19,245
create a function out of it, this one will return an Array (string) of mac address:
to get the actual mac address, you need to parse the returned array : mid(a(I), instrrev(a(I), " ")+1)

dim arr as variant
dim v as variant

arr=getLocalMACAddress()
for each v in arr
debug.print v
next
Code:
Public Function getLocalMACAddress() As Variant
    ' get a list of enabled adaptor names and MAC addresses
    ' from msdn.microsoft.com/en-us/library/windows/desktop/aa394217(v=vs.85).aspx
    
    Dim objVMI As Object
    Dim vAdptr As Variant
    Dim objAdptr As Object
    Dim arr() As String
    Dim i As Integer
    
    Set objVMI = GetObject("winmgmts:\\" & "." & "\root\cimv2")
    Set vAdptr = objVMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    
    For Each objAdptr In vAdptr
        ReDim Preserve arr(i)
        arr(i) = objAdptr.Caption & " " & objAdptr.MACAddress
        i = i + 1
        'Debug.Print objAdptr.Caption & " " & objAdptr.MACAddress
    Next objAdptr
    getLocalMACAddress = arr
End Function
 

Users who are viewing this thread

Top Bottom