Question:
How can I return the serial number of an HD installed in the computer?
Solution:
It is possible to do so by using the script below. It lists all serial numbers of the HDs and disk units in the computer. In this example, the script is fired in any of the application’s buttons’ Click() event:
Sub CommandButton1_Click()
‘Script to display HDs’ serial numbers
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_PhysicalMedia”)
For Each objItem In colItems
str = “SerialNumber: “ & objItem.SerialNumber
‘Using a message box to to display the HDs’ serial number
MsgBox str
Next
End Sub