In order to get the USB storage device serial number and other manufacturer information (NOT volume serial, only the unique one, the one that will not change after a format, physical one) using USBPhysic library and FoxPro you need to do the following 3 easy steps:
(1) Load USBPhysic library and declare the imported library functions:
Object: Form1 ; Procedure: Load ;
DECLARE INTEGER GetUSBPhysicInfo IN "USBPhysic.dll" AS USB_Info INTEGER diskIndex, INTEGER InfoType, STRING pHddInfo
(2) Call the Init function to initialize the user computer USB storage devices and get their total count:
Object: Form1 ; Procedure: Show ;
IF tDiscs > 0 THEN
FOR i=0 TO tDiscs-1 STEP 1
This.Combo1.AddItem (ALLTRIM(STR(i)))
NEXT
ENDIF
(3) Now that you have the total USB devices count you can query for the manufacturer information passing the disk index to the GetUSBPhysicInfo function:
Objec: Command1 ; Procedure: Show ;
iDiskNo = Form1.Combo1.ListIndex-1
iReturn = USB_Info(iDiskNo, 0, @sBuffer) && 0 = serial number
Form1.Text2.Value=sBuffer
iReturn = USB_Info(iDiskNo, 1, @sBuffer) && 1 = product name
Form1.Text1.Value=sBuffer
iReturn = USB_Info(iDiskNo, 2, @sBuffer) && 2 = manufacturer
Form1.Text3.Value=sBuffer
iReturn = USB_Info(iDiskNo, 3, @sBuffer) && 3 = drive letter mapped on Windows
Form1.Text4.Value=sBuffer
A complete Visual FoxPro 9.0 project is available for download in the resource area of the project here