Get manufacturer’s serial number from hard disk in VB Script

Below is a VB Script to get the original Manufacturer serial number of hard drive that was set from the factory. This is different from the serial number set by windows during formatting.

I had to put this script here because i spent so much time online trying to find a vb script that can get this serial number and found none. I hope it will one day save someone the stress i went through to get the code to do this. This code is useful for programmers who are looking to secure their application from piracy by locking it to hardware.

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)
Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_PhysicalMedia”)
k = 0
serial = “”
For Each objItem in colItems
Wscript.Echo “Serial Number: ” & objItem.SerialNumber