Results 1 to 10 of 10

Thread: read serial number of external usb hard drive

  1. #1

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    read serial number of external usb hard drive

    Can anyone help me with code to read serial number of usb external harddrives?
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: read serial number of external usb hard drive

    The volume serial number is pretty easy to get, but it is also trivial for users to change.

    The media serial number is much harder to get. Most attempts use WMI, but you can't rely on WMI being present and active (it's a heavy service intended for administration, not applications). Worse yet many manufacturers don't even use unique values.

  3. #3
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: read serial number of external usb hard drive

    Try;

    Code:
    Function GetDriveSerialNumber$(Path$)
    
        Dim a$, f%
        
        ShellAndWait Environ$("COMSPEC") & " /C VOL " & Left$(Path$, 2) & " > temp.txt", vbHide
        
        f = FreeFile
        
        Open "temp.txt" For Input As f
            a$ = Input$(LOF(f), f)
        Close f
        Kill "temp.txt"
        
        a$ = Replace$(a$, vbCrLf, "")
        
        GetDriveSerialNumber$ = Right$(Trim$(a$), 9)
    
    End Function

  4. #4
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: read serial number of external usb hard drive

    You'll need a ShellAndWait Sub of course but there are plenty of examples around if you do not already have one.

  5. #5

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: read serial number of external usb hard drive

    its returning the volume serial number.
    i need the manufacturer or firmware serial number
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  6. #6
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: read serial number of external usb hard drive

    Ok...

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

    Re: read serial number of external usb hard drive

    i posted an example using wmi, to find serial number from usb memory sticks, in this forum, here
    http://www.vbforums.com/showthread.p...+serial+number
    i assume this will also work for hard disks

    note you may need to use elevated privilages if you are running as limited user, you may also be able to use apis
    i do not remember if APIs that return serial number of HDD will work for usb, but they will not work as limited user
    see this thread for more info
    http://www.vbforums.com/showthread.p...ght=hdd+serial

    edit on testing i believe the code in the first link returns the id of the usb interface, not the hdd serial number
    and the wmi for getting serial number of hdd also appears to not work with external drives
    Last edited by westconn1; Feb 23rd, 2011 at 04:16 AM.
    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

  8. #8
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: read serial number of external usb hard drive

    hey using http://www.vbforums.com/showthread.p...ght=hdd+serial can u track a stolen pc?
    Attached Files Attached Files
    Last edited by flyhigh; Feb 23rd, 2011 at 06:46 AM.

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

    Re: read serial number of external usb hard drive

    can u track a stolen pc?
    only if some code runs on start up and no one reformats, changes user, has internet connection etc, etc

    i might think about it some more
    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

  10. #10
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: read serial number of external usb hard drive

    yes on the harddrive but the motherboard doesnot change does it?

Tags for this Thread

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