Announcement

Collapse
No announcement yet.

USB Memory Volume Serial Number

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • USB Memory Volume Serial Number

    Can anyone tell me if there is a way to identify a USB Pen type of memory / Disk drive.
    The normal way is to use ;

    GetVolumeInformation lZ, _
    VolInf(lCnt).VolName, _
    SIZEOF (VolInf(lCnt).VolName), _
    VolInf(lCnt).VolSerial, _
    VolInf(lCnt).FileLength, _
    VolInf(lCnt).FileSysFlags, _
    VolInf(lCnt).FileSysName, _
    SIZEOF(VolInf(lCnt).FileSysName)
    …....................

    With USB Memory the VolSerial changes each time the drive is formatted.
    Any help would be apprecated.

  • #2
    A volume is a partition, not a physical drive, so it's "serial" will change each format.

    See the GetDriveType API function to query the type of drive a volume is located.
    The following shows the message box for any USB drive I plug in:

    Code:
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
     
    Function PBMain
      If GetDriveType("f:\") = %DRIVE_REMOVABLE Then
         ? "Drive is removable"
      End If
    End Function
    There is no known way to reliably get the actual physical serial number of a removable drive.
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      Ed Turnbull

      Thanks for the reply. Sorry I did not make the question clear. What I need is to identify which of over 100 USB memory sticks has been plugged in.
      Ed

      Comment


      • #4
        Apart from using the volume serial number, it can't be done (AFAIK). The USB connection does not allow things like SMART operations to be used.

        If you're not formatting them each time, you could put a file on there which contains a unique code to identify it.
        kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

        Comment


        • #5
          From lvr.com in the FAQ section:
          During device testing, we attach many devices that are identical except for the serial numbers. How can I prevent Windows from asking to install a new driver every time a device is attached?

          This method causes Windows 2000 and XP to ignore a device's serial number. It's recommended for test environments only.

          This registry key controls whether Windows uses or ignores device serial numbers:

          [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags]

          It's possible to ignore all serial numbers, though this approach is NOT recommended. To ignore all serial numbers, in the above key, change this value to zero:

          GlobalDisableSerNumGen = 1

          To ignore the serial number for an individual device, create an entry under the above ...\UsbFlags key. The name must
          start with "IgnoreHWSerNum" followed by the vendor and product ID of the device. A value of 1 = disable the serial number.

          Example (Vendor ID = 0925h, Product ID = 016Ah):

          IgnoreHWSerNum0925016A= 1

          (Thanks to Dieter Fauth for this answer!)
          Perhaps the following links can point you in the right direction:

          MSDN on IOCTL_STORAGE_QUERY_PROPERTY

          Should be where to get Serial Number

          IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER Control Code


          http://www.cfdan.com/posts/Retrievin...ng_C_Sharp.cfm
          Last edited by Scott Hauser; 26 Feb 2009, 01:36 PM. Reason: Added MSDN links
          The most exasperating part of the "rat race" is how often the rats are in the lead!

          Comment


          • #6
            use a file?

            Ed, would it be possible to place a simple text file on every USB device with the single name: serialNo.txt that contains the ID for the specified USB device? then, your program would read the file to identify the device, rather than depend on something that would be changable. Of course, you could write the file in binary mode, so it couldn't be easily changed by the user.

            regards, Ian.
            :) IRC :)

            Comment


            • #7
              Ed Turnbull

              Thanks all for the posts. I would rather use information that cannot be changed on the memory stick by re formatting. These memory sticks will be posted to blind people ( on a weekly basis ) and we need a foolproof way of knowing which ones have been returned. The Volume label or serial number will work fine until someone reformats the device. I will rethink the process to see if there is a different way to track the devices.
              Ed

              Comment


              • #8
                >I will rethink the process to see if there is a different way to track the devices.

                How putting a piece of masking tape on each drive with its "drive number" written in ink thereon, plus a sign-out/sign-in sheet on a clipboard?

                Collect a security deposit when checked out. Refund when checked in. Update log when doing either.

                (Hey, you asked!)
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  I just remembered, if you open the disk using CreateFile - PhysicalDriveX then the MBR signature can be retrieved. You can get the physical drive number by using DeviceIoControl with the drive handle returned by CreateFile("DriveNo:\"), open that, then read first sector (sector zero), MBR signature DWORD is located at byte #441.

                  The MBR signature may be zero or duplicate, but it's worth a try..
                  kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                  Comment


                  • #10
                    I found a snippet from Greg Turgeon that could be of use to obtain the serial number if you wish to modify it.

                    Greg's code sample
                    The most exasperating part of the "rat race" is how often the rats are in the lead!

                    Comment


                    • #11
                      Somewhere in the back of my mind, you may want to search for one of the following

                      "USB"
                      USB "Kev Peel"
                      "USB Incomplete"
                      "USB Network Attach"

                      Unfortunately they all point at lil ole' me....but it was truly Kev that got me started in the USB world, so you will want to search for his posts more than mine :wavey:
                      Engineer's Motto: If it aint broke take it apart and fix it

                      "If at 1st you don't succeed... call it version 1.0"

                      "Half of Programming is coding"....."The other 90% is DEBUGGING"

                      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                      Comment


                      • #12
                        Hi Ed,

                        José Roca's WMI examples might get you what you need. A good start would be this one. Look at the PnP Device ID (which is non-volatile and doesn't change with formatting).

                        Results are similar to this (for one of my own USB sticks):

                        Code:
                        PNP Device ID = USB\VID_0ED1&PID_6986\U0XDQ95B
                        Description = USB Mass Storage Device
                        Regards,

                        Pete.

                        Comment


                        • #13
                          I found a snippet from Greg Turgeon that could be of use to obtain the serial number if you wish to modify it.
                          Any code that tries to use VendorIdOffset/ProductIdOffset doesn't work reliably on USB hard drives, and not at all on memory sticks (you get a 1-byte value back). The product serial number remains elusive.

                          I've tried them all folks - IOCTL_STORAGE_QUERY_PROPERTY, SMART_RCV_DRIVE_DATA (using SCSI), and other methods. The only thing I didn't try is WMI which might have a solution.
                          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                          Comment

                          Working...
                          X