3

I distribute licensed software and have a pretty good VBA method of registering and identifying the registered PC as being unique. I use a combination of Motherboard ID + Processor ID + HD ID (for ID read Serial number as well). So far after registering over 1000 devices I have yet to see a duplicate.

Now I need to extent this VBA functionality to the Apple Mac OSx environment. Can anyone help me with the VBA code to get a 'number' from a MAC that is unique to that machine. Obviously the PC code won't work.

Community
  • 1
  • 1
Mike Eburne
  • 351
  • 2
  • 7
  • 21

1 Answers1

0

You could try the machines serial number using this Function. It will work on Mac or PC

Function GetPCSerialNumber()
'   V1.1
#If Mac Then
    Dim PCSerialNumber, StrOffset
    PCSerialNumber = MacScript("do shell script ""ioreg -l | grep IOPlatformSerialNumber""")
    StrOffset = InStr(PCSerialNumber, " = """)
    PCSerialNumber = Mid(PCSerialNumber, StrOffset + 4, 999)
    GetPCSerialNumber = "{Mac}" & Left(PCSerialNumber, Len(PCSerialNumber) - 1)
#Else
'   wmic bios get * /format:list
    Dim objWMIService As Object
    Dim colItems As Variant
    Dim objItem
    Dim strMsg As String

    Set objWMIService = GetObject("winmgmts://./root/cimv2")

    Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS where PrimaryBIOS = true", , 48)

    For Each objItem In colItems
        strMsg = objItem.SerialNumber
    Next

    GetPCSerialNumber = strMsg
#End If

You could also use Excel's own function [in VBA] ENVIRON(), to get the values of [PC] environment variables e.g. ENVIRON("USERNAME") or ENVIRON("COMPUTERNAME"), you could access this in Excel by creating another function GETENVIRON():

Function GetEnviron(ByVal EnvironmentVariableName As String)
'   V1.1
    GetEnviron = Environ(EnvironmentVariableName)
End Function

Note that on a Mac, the equivalent of a PC's USERNAME environment variable is USER or LOGNAME.

On a Mac there are far less environment variables of use (Try ENV in a Terminal windows to see)