Retrieving serial number from hard drive to access table field

Patricksss

New member
Local time
Today, 10:27
Joined
Apr 12, 2022
Messages
4
Hello experts. I am trying to make access retrieve serial number of the hard drive or motherboard then store the value in the table field. How can I achieve this?
 
Look in this thread:


This shows a code snippet for the HDD serial number.

Also this thread:


Shows a code snippet for CPU serial number.

And finally:


which discusses reading from the computer's registry for information to identify the system.

Be aware that if your goal is some kind of "hard license" that blocks use on another machine, you might make it impossible for your customer to upgrade his/her system without some serious help from you.
 
hd serial:
Code:
' credit to my book:
' managing enterprise systems
' with the windows script host
'
' by stein borge
' (c) 2002
' apress
'
' pg.285
'
' arnelgp
'
Public Function HDSerialNumber() As String
Dim strComputer As String
Dim objWMIService As Object
Dim objItem As Object
Dim colItems As Object
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
                                        "SELECT * FROM Win32_DiskDrive")
Dim i As Integer
For Each objItem In colItems
    Debug.Print i, objItem.NAME, objItem.SerialNumber
    i = i + 1
    If InStr(objItem.NAME, "PHYSICALDRIVE0") > 0 Then
        HDSerialNumber = objItem.SerialNumber
    End If
Next
End Function
 
other functions:
Code:
'http://vb-helper.com/howto_get_cpu_serial_number_id.html
Public Function SystemSerialNumber() As String
Dim mother_boards As Variant
Dim board As Variant
Dim wmi As Variant
Dim serial_numbers As String

    ' Get the Windows Management Instrumentation object.
    Set wmi = GetObject("WinMgmts:")

    ' Get the "base boards" (mother boards).
    Set mother_boards = wmi.InstancesOf("Win32_BaseBoard")
    For Each board In mother_boards
        serial_numbers = serial_numbers & ", " & board.SerialNumber
    Next board
    If Len(serial_numbers) > 0 Then serial_numbers = Mid$(serial_numbers, 3)

    SystemSerialNumber = serial_numbers
End Function
'http://vb-helper.com/howto_get_cpu_serial_number_id.html
Public Function CpuId() As String
Dim computer As String
Dim wmi As Variant
Dim processors As Variant
Dim cpu As Variant
Dim cpu_ids As String

    computer = "."
    Set wmi = GetObject("winmgmts:" & _
        "{impersonationLevel=impersonate}!\\" & _
        computer & "\root\cimv2")
    Set processors = wmi.ExecQuery("Select * from Win32_Processor")

    For Each cpu In processors
        cpu_ids = cpu_ids & ", " & cpu.ProcessorId
    Next cpu
    If Len(cpu_ids) > 0 Then cpu_ids = Mid$(cpu_ids, 3)

    CpuId = cpu_ids
End Function
 
Hi @Patricksss

Regarding your other question at


You can use an UPDATE or APPEND query to store the serial number into a table.
 

Users who are viewing this thread

Back
Top Bottom