Can anyone help me with code to read serial number of usb external harddrives?
Printable View
Can anyone help me with code to read serial number of usb external harddrives?
The volume serial number is pretty easy to get, but it is also trivial for users to change.
The media serial number is much harder to get. Most attempts use WMI, but you can't rely on WMI being present and active (it's a heavy service intended for administration, not applications). Worse yet many manufacturers don't even use unique values.
Try;
Code:Function GetDriveSerialNumber$(Path$)
Dim a$, f%
ShellAndWait Environ$("COMSPEC") & " /C VOL " & Left$(Path$, 2) & " > temp.txt", vbHide
f = FreeFile
Open "temp.txt" For Input As f
a$ = Input$(LOF(f), f)
Close f
Kill "temp.txt"
a$ = Replace$(a$, vbCrLf, "")
GetDriveSerialNumber$ = Right$(Trim$(a$), 9)
End Function
You'll need a ShellAndWait Sub of course but there are plenty of examples around if you do not already have one.
its returning the volume serial number.
i need the manufacturer or firmware serial number
Ok...
i posted an example using wmi, to find serial number from usb memory sticks, in this forum, here
http://www.vbforums.com/showthread.p...+serial+number
i assume this will also work for hard disks
note you may need to use elevated privilages if you are running as limited user, you may also be able to use apis
i do not remember if APIs that return serial number of HDD will work for usb, but they will not work as limited user
see this thread for more info
http://www.vbforums.com/showthread.p...ght=hdd+serial
edit on testing i believe the code in the first link returns the id of the usb interface, not the hdd serial number
and the wmi for getting serial number of hdd also appears to not work with external drives
hey using http://www.vbforums.com/showthread.p...ght=hdd+serial can u track a stolen pc?
only if some code runs on start up and no one reformats, changes user, has internet connection etc, etcQuote:
can u track a stolen pc?
i might think about it some more
yes on the harddrive but the motherboard doesnot change does it?