Hello,

I would like to read the serial-number of a USB memory-stick
programmatically; searching the net I found the following VB-script,
which returns the serial-number assigned when the drive is formatted.
Unfortunately I do not know how to convert this to RB-code...could
someone please help?

Sub ShowDriveInfo(drvpath)
   Dim fs, d, s, t
   Set fs = CreateObject("Scripting.FileSystemObject")
   Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(drvpath)))
   Select Case d.DriveType
       Case 0: t = "Unknown"
       Case 1: t = "Removable"
       Case 2: t = "Fixed"
       Case 3: t = "Network"
       Case 4: t = "CD-ROM"
       Case 5: t = "RAM Disk"
   End Select
   s = "Drive " & d.DriveLetter & ": - " & t
   s = s & vbCrLf & "SN: " & *d.SerialNumber*
   MsgBox s
End Sub

Secondly, I would rather like to read the hardware-serial-number of
the USB-device; again, I found some VB-source, which I - crudely -
converted with the help of Aarons 'VB Declare Converter' to RB-code;
but it doesnt work (under Windows):

(new project with an editfield and a pushbutton on the window, in the
pbs-action-handler:)

 Declare Function GetVolumeSerialNumber Lib "kernel32.dll" Alias
"GetVolumeInformationA" ( lpRootPathName As CString,
lpVolumeNameBuffer As CString, nVolumeNameSize As Integer, ByRef
lpVolumeSerialNumber As Integer, ByRef lpMaximumComponentLength As
Integer, ByRef lpFileSystemFlags As Integer, lpFileSystemNameBuffer As
CString, nFileSystemNameSize As Integer ) As Integer

 Dim VolLabel As String
 Dim VolSize As Integer 'Long
 Dim Serial As Integer '
 Dim MaxLen As Integer '
 Dim Flags As Integer '
 Dim Name As String
 Dim NameSize As Integer '
 Dim s As String

 dim RootPath,VolumeSerialNumber as string

 RootPath = EditField1.Text

 If GetVolumeSerialNumber(RootPath, VolLabel, VolSize, Serial,
MaxLen, Flags, Name, NameSize) <> 0 Then
   'Create an 8 character string
   's = Hex(Serial)
   'Adds the '-' between the first 4 characters and the last 4 characters
   VolumeSerialNumber = s 'Left(s, 4) + "-" + Right(s, 4) + EndOfLine + s
 Else
   'If the call to API function fails the function returns a zero serial number
   VolumeSerialNumber = "0000-0000"
 End If

 EditField1.Text = VolumeSerialNumber 'Shows the serial number of
your Hard Disk

For the Mac I have only found to ask the shell to pass back the serial
number: ioreg -c IOUSBDevice | grep "USB Serial Number

TIA.

chris henkel
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to