For me yes, but I'm still too noob in programming and I prefer to let other people (Pure Basic Mentor) to answer this question.IdeasVacuum wrote:Is that magic number 8 safe for 32bit and 64bit?
Obtain the serial number of USB key
Re: Obtain the serial number of USB key
➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect
Re: Obtain the serial number of USB key
Thanks a lot falsam for your WMI Tutorial, before I read it, i had no ideas of how to use WMI at all !!
WMI was an unreachable micro$oft secret for me...
Now , i think that i would be able play with my usb keys and compare the result with usbdeview
but i doubt of the value given as serial number by this software....
I have several keys from the same manufacturer and the vendorID given seems ok ! the modelID too, but not the serial...
Great JOB falsam ! A Great MERCI !
WMI was an unreachable micro$oft secret for me...
Now , i think that i would be able play with my usb keys and compare the result with usbdeview
but i doubt of the value given as serial number by this software....
I have several keys from the same manufacturer and the vendorID given seems ok ! the modelID too, but not the serial...
Great JOB falsam ! A Great MERCI !

Re: Obtain the serial number of USB key
Good shot falsam
But WMI is not always enabled
Beside next is more simple
Tested with PB x86 - PB x64 Win 7 x64
But WMI is not always enabled
Beside next is more simple
Tested with PB x86 - PB x64 Win 7 x64
Code: Select all
Global Result,SerialNum.q , a.q , b.q , VolumeName.s
Drives$ = Space(#MAX_PATH)
Result = GetLogicalDriveStrings_(#MAX_PATH,@Drives$)
For x = 0 To Result - 4 Step 4
Type$ = PeekS(@Drives$+x,3)
Debug Type$
If GetDriveType_(Type$) = 0
Debug "The drive type cannot be determined"
ElseIf GetDriveType_(Type$) = 2
Debug "REMOVABLE DRIVE"
ElseIf GetDriveType_(Type$) = 3
Debug "FIXED DRIVE "
ElseIf GetDriveType_(Type$) = 4
Debug "REMOTE DRIVE"
ElseIf GetDriveType_(Type$) = 5
Debug "CDROM DRIVE"
ElseIf GetDriveType_(Type$) = 1
Debug "RAMDISK DRIVE"
EndIf
GetVolumeInformation_(Type$, @VolumeName, Len(VolumeName), @SerialNum, a, b, 0, 0)
Debug "Serial Num :"+RSet(Hex(SerialNum),8,"0")
Debug " "
SerialNum = 0
Next
Egypt my love
Re: Obtain the serial number of USB key
Hello Rashad. Thank you for your code which in this case is better. The result is the same as the WMI query.
With your code on my computer
@NabDa : Welcome to the forum. I have not seen your speudo on the French forum. I hope to see you also on the French forum. A bientôt.
PS : WMI also allows to know information on remote computers.
With your code on my computer
Result With WMIC:\
FIXED DRIVE
Serial Num :5CFBA1A6
D:\
FIXED DRIVE
Serial Num :A057F37A
E:\
FIXED DRIVE
Serial Num :44DD6D54
F:\
CDROM DRIVE
Serial Num :00000000
G:\
CDROM DRIVE
Serial Num :3343FF32
H:\
REMOVABLE DRIVE
Serial Num :100C1840
Z:\
REMOTE DRIVE
Serial Num :00000000
This forum is very reactive and ...... I love itC:
Description=Disque fixe local
VolumeSerialNumber=5CFBA1A6
D:
Description=Disque fixe local
SerialNumber=A057F37A
Caption=E:
Description=Disque fixe local
VolumeSerialNumber=44DD6D54
Caption=F:
Description=Disque CD-ROM
VolumeSerialNumber=
Caption=G:
Description=Disque CD-ROM
VolumeSerialNumber=3343FF32
Caption=H:
Description=Disque amovible
VolumeSerialNumber=100C1840
Caption=Z:
Description=Connexion réseau
VolumeSerialNumber=

@NabDa : Welcome to the forum. I have not seen your speudo on the French forum. I hope to see you also on the French forum. A bientôt.

PS : WMI also allows to know information on remote computers.
➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect
Re: Obtain the serial number of USB key
It should be noted that those are VOLUME ID's -- NOT drive serial #'s.
Volume id's can be changed; and if you format a drive, the volume id will change, however, a drives serial # will not.
Volume id's can be changed; and if you format a drive, the volume id will change, however, a drives serial # will not.
Re: Obtain the serial number of USB key
If you formatted your usb, serial number changes.jassing wrote:It should be noted that those are VOLUME ID's -- NOT drive serial #'s.
Volume id's can be changed; and if you format a drive, the volume id will change, however, a drives serial # will not.
with the same usb key.
after formattingCaption=G:
Description=Disque amovible
VolumeName=USBDISKPRO
VolumeSerialNumber=04EC52B0
Caption=G:
Description=Disque amovible
VolumeName=Data 2
VolumeSerialNumber=8A745A86
➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect
Re: Obtain the serial number of USB key
I'm not sure that the process is good, but the result is consistent with those that I find with other software that detects serial numbers. I tested this code with 5 usb.
If possible, test this code and feedback
Thanks.
If possible, test this code and feedback

Code: Select all
;Usb drive : Read Serial Number
IncludeFile "WMIQuery.pbi"
Global Buffer.s
NewList WMIResult.WMIClass()
If WMIQuery("SELECT PNPDeviceID FROM Win32_DiskDrive WHERE InterfaceType='USB'", WMIResult())
ForEach WMIResult()
Debug WMIResult()\Property + "=" + WMIResult()\Value
Buffer = StringField(WMIResult()\Value, CountString(WMIResult()\Value, "\")+1, "\")
Debug "Serial number " + Left(Buffer, Len(Buffer)-2)
Next
EndIf
➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect
Re: Obtain the serial number of USB key
Similar using Commate Plus:
I remember getting this code from the forum but can't remember who to give credit to, sorry.
Code: Select all
XIncludeFile "COMatePLUS.pbi"
Procedure DD_Info1()
Define.COMateObject objWMIService, DDInfo
colDDInfo.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colDDInfo = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_USBHub')")
;colDDInfo = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_DiskDrive WHERE InterfaceType='USB')")
If colDDInfo
DDInfo = colDDInfo\GetNextObject()
While DDInfo
Debug "Description : " + DDInfo\GetStringProperty("Description")
Debug "Name : " + DDInfo\GetStringProperty("Name")
Debug "DeviceID : " +DDInfo\GetStringProperty("PNPDeviceID")
DDInfo\Release()
DDInfo = colDDInfo\GetNextObject()
Wend
colDDInfo\Release()
EndIf
objWMIService\Release()
Else
MessageRequester("Error", "DDInfo")
EndIf
EndProcedure