Results 1 to 10 of 10

Thread: [RESOLVED] serial number of pen drive

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    san francisco ca
    Posts
    120

    Resolved [RESOLVED] serial number of pen drive

    hello..
    somebody can helpme about get the serial number of pen drive ( not volume information).
    thanks all...

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: serial number of pen drive

    here is some code to get serial number, if you have more than 1 usb drive you will need to make an array or simething, as obviously this will only get the serial number of the last usb drive
    vb Code:
    1. strComputer = "."
    2. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    3. Set colitems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", , 48)
    4. For Each objitem In colitems
    5. If objitem.interfacetype = "USB" Then sernum = objitem.pnpdeviceid
    6. Next
    7. sernum = Mid(sernum, InStrRev(sernum, "\") + 1)
    8. sernum = Left(sernum, InStr(sernum, "&") - 1)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    New Member
    Join Date
    Jul 2009
    Posts
    1

    Re: serial number of pen drive

    READ USB serial number with VB.
    You are just too good Man. I looked high and dry on the net for this code but none came even close enough. If u cud make it detect all usb drives and their serial numbers in a list,you've got a winner.
    Anyway, i bow to the master.
    Last edited by Laserfinder; Jul 21st, 2009 at 11:01 AM.

  4. #4
    New Member
    Join Date
    Feb 2010
    Posts
    1

    Re: serial number of pen drive

    The code is nice and it works. But new Pen Drive does not have Serial No. Old Transcend have serial No. But now dont have it. Is there any chance to make a serial No by our own for the pen drive or is there any pen drive with Serial No in Market.

    Thanks in advance
    Thiyagu

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    san francisco ca
    Posts
    120

    Re: serial number of pen drive

    can you post some complete example?
    its because i dont know how to use that sample...
    thanks..

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: serial number of pen drive

    that is complete, put command button, with the above code for click event, the serial number is in the variable sernum
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    san francisco ca
    Posts
    120

    Re: serial number of pen drive

    thanks that works

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] serial number of pen drive

    the code does return all usb drives, just as it stands it only retains the last one, just add each to a listbox or an array to work with
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    Junior Member
    Join Date
    Nov 2009
    Posts
    24

    Re: [RESOLVED] serial number of pen drive

    westconn1, your code is fantastic! Thank you.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] serial number of pen drive

    ask before you buy, as they are now so cheap, maybe the manufacturer don't bother with serial number any more, i think all mine have, but i have not bought any new for a while
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width