Hardware fingerprint

User avatar
ErikJan
BronzeLounger
Posts: 1228
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Hardware fingerprint

Post by ErikJan »

Testing a not-too-complex way to get some sort of system fingerprint. The following code shows three entries, one related to the CPU, the second to the motherboard and the last connected to the hard disk.
I'm OK if some of the strings could be empty or zero (as long as not all of them are). I'm wondering if and how this runs under Win32 (I can probably test that myself) and on Apple hardware. I'd appreciate if Someone who could maybe test this and let me know. For all others, this is FYI (and enhancements and suggestions are welcome as always)

Code: Select all

Option Explicit

Sub t()
    Dim S As String
    S = "Proc rev.:" & vbTab & vbTab & Environ("PROCESSOR_REVISION") & vbCrLf
    S = S & "MB Serial:" & vbTab & MBSerialNumber & vbCrLf
    S = S & "HD Manuf Serial:" & vbTab & HD_Manu_Serial
    MsgBox S, vbInformation, "Hardware ID"
End Sub
Public Function MBSerialNumber() As String
'Ref to Microsoft WMI Scripting Library required
    Dim WMI As Object, oItems As Object, oItem As Object
    '
    Set WMI = GetObject("WinMgmts:")
    Set oItems = WMI.InstancesOf("Win32_BaseBoard")
    '
    For Each oItem In oItems
        MBSerialNumber = oItem.SerialNumber
        Exit For
    Next
End Function
Function HD_Manu_Serial() As String
    Dim oWMI As Object, oItems As Object, oItem As Object, Ser As String
    Set oWMI = GetObject("winmgmts:") '{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set oItems = oWMI.ExecQuery("Select * from Win32_DiskDrive")
    '
    For Each oItem In oItems
        On Error Resume Next
'Debug.Print "Index: " & oItem.Index
'Debug.Print "InterfaceType: " & oItem.InterfaceType
'Debug.Print "DeviceID: " & oItem.DeviceID
'Debug.Print "Model: " & oItem.Model
'Debug.Print "Manufacturer SerialNo: " & oItem.SerialNumber
        If oItem.InterfaceType <> "USB" And oItem.SerialNumber <> 0 Then Ser = oItem.SerialNumber
        On Error GoTo 0
    Next
    Set oItem = Nothing
    Set oItems = Nothing
    Set oWMI = Nothing
    '
    If Right(Ser, 1) = "." Then Ser = Left(Ser, Len(Ser) - 1)
    HD_Manu_Serial = Ser
End Function

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Hardware fingerprint

Post by HansV »

I don't think the Microsoft WMI Scripting Library is available in MacOS (the W stands for Windows).
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1228
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Hardware fingerprint

Post by ErikJan »

Hmmm. That is true of course... didn't realize that. Anyone with less OS dependent ways to get to this (or similar unique) info in another way?

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Hardware fingerprint

Post by jstevens »

ErikJan,

On a MAC you can generate a "System Report": Click on the Apple (Upper left corner)>About This Mac>System Report

I'm not familiar with scripting on the MAC side to get the information but it still available.
EL_102.png
You do not have the required permissions to view the files attached to this post.
Regards,
John

User avatar
ErikJan
BronzeLounger
Posts: 1228
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Hardware fingerprint

Post by ErikJan »

Thanks... there is a compiler directive that I can use to identify a Mac. I can use that to find out (but that doesn't provide me Mac hardware info).

Code: Select all

#If Mac Then
    Win_Mac = "Mac"
#Else
    Win_Mac = "Windows"
#End If