Multiplatform Windows and MAC computer indentify

Viewed 215

is there any multiplatform method to identify user account, system or entire computer? Something like:

CreateObject("Scripting.FileSystemObject").GetDrive("C:\").SerialNumber

It may use some combinations of username and other variables to build (quite) unique ID text/number. Maybe should I use Environ? But where can I find complete list multiplatform Environ working variables? It may use OS identification also.

EDIT some starting code to clarify my question

Sub GenerateID()

    #If Mac Then
    '------- Mac ---------------
        MsgBox MacIdNumber
    #Else
    '------- Windows -----------
        MsgBox WindowsIdNumber
    #End If
    End Sub

Function MacIdNumber() As Long

    Dim str1, str2, str3 ' str4, str5...
        str1 = VBA.Environ$("USER")
        str2 = Application.Version
        str3 = Application.OperatingSystem
        ' and here I am looking for another ideas
        ' str4 = ...???
    MacIdNumber = CreateUniqueId(str1, str2, str3)
    End Function

Function WindowsIdNumber() As Long

    Dim str1, str2, str3, str4 ', str5...
        str1 = CreateObject("Scripting.FileSystemObject").GetDrive("C:\").SerialNumber
        str2 = VBA.Environ$("USERNAME")
        str3 = Application.Version
        str4 = Application.OperatingSystem
        ' and here I am looking for another ideas
        ' str5 = ...???
        ' but maybe for Windows disc SerialNumber is enough
    WindowsIdNumber = CreateUniqueId(str1, str2, str3, str4)
    End Function

Function CreateUniqueId(ParamArray str() As Variant) As Long
    
    ' here I'll make checksum
    ' some calculations...
    End Function

I am trying to get as unique ID strings as possible (but I know it probably won't be 100% unique).

It must work in reliable way for MAC 2016 and higher and Windows versions of course. So If you give an idea with apple script- I must be sure that no endless loop/ error occurs.

I am Windows user and I am not able to test it on MAC right now.

2 Answers

Looks like the answer is "no".

According to https://docs.microsoft.com/en-us/office/vba/api/overview/office-mac

Office 2016 for Mac is sandboxed

Unlike other versions of Office apps that support VBA, Office 2016 for Mac apps are sandboxed.

Sandboxing restricts the apps from accessing resources outside the app container. This affects any add-ins or macros that involve file access or communication across processes. You can minimize the effects of sandboxing by using the new commands described in the following section.

What this says to me is that you are going to have to use a different, native, scripting language to get the information you want in to Excel.

Is this what you are trying? tested it on both Excel 2016 (Mac/Windows)

Option Explicit

Sub GenerateID()
    #If Mac Then
    '------- Mac ---------------
        MsgBox GetUniqueID("Mac")
    #Else
    '------- Windows -----------
        MsgBox GetUniqueID("Win")
    #End If
End Sub

Private Function GetUniqueID(sys As String) As String
    Select Case sys
    Case "Mac"
        '~~> Ref: http://www.rondebruin.nl/mac/mac003.htm
        Dim AppleScript As String
        AppleScript = "set uuid to do shell script ""system_profiler SPHardwareDataType" & _
                      " | awk '/Hardware UUID:/ {print $NF}'"""
        
        On Error Resume Next
        GetUniqueID = MacScript(AppleScript)
        On Error GoTo 0
    Case "Win"
        GetUniqueID = CreateObject("Scripting.FileSystemObject").GetDrive("C:\").SerialNumber
    End Select
End Function

Screenshot

enter image description here

Related