VBS Script – Get USB Drive Serial Number

Many USB drives (particularly USB ‘thumb drives’) do not have the unique serial number printed on the outside.

Sometimes there is a need to use the unique hardware serial number for asset record management or auditing.

The following script can be used to get the serial number for a USB Drive (or hard drive).


When you run the script it will prompt for the drive letter (e.g. E)


After entering the ldrive letter and clicking ‘OK’ it will return the serial number for the device.

It will also return the drive type, file system, free space (in MB) and total size (in MB).

The serial number is presented in a text box which allows you to copy and paste it into another window.


VBS Script:

strComputer = "."
usbdrive = InputBox ("Enter the USB Drive Letter")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
str = ""
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where DeviceID ='" & usbdrive & ":'")
For Each objItem In colItems
   SerialNumber = objItem.VolumeSerialNumber
   DriveType = objItem.Description
   FileSystem = objItem.FileSystem
   FreeSpace = (objItem.FreeSpace / 1048576)
   TotalSize = (objItem.Size / 1048576)


tmp = inputBox ("Drive Type:  " & DriveType & vbNewLine & "File System:  " & FileSystem & vbNewLine & "Free Space:  " & FreeSpace & "   MB"  & vbNewLine & "Total Size:  " & TotalSize & "   MB" , "USB Drive Serial Number",SerialNumber)

Related Articles

Leave a Reply

Your email address will not be published.