dcsimg
Results 1 to 29 of 29

Thread: Get serial number of all hard disks and partitions in it

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Get serial number of all hard disks and partitions in it

    I want to get all physical hard disk serial number(not volume serial number of drives) and partitions present in them.

    Actually I used implementation from DISKID32 to get all hard disks serial number , but this will not give partitions in the hard disk.So I planned to use some other method.

    Below code gives get serial number of physical hard disk and also find partitions in the each harddisks.

    Code:
    ComputerName = "."
    Set wmiServices  = GetObject ( _
        "winmgmts:{impersonationLevel=Impersonate}!//" _
        & ComputerName)
    ' Get physical disk drive
    Set wmiDiskDrives =  wmiServices.ExecQuery ( _
        "SELECT * FROM Win32_DiskDrive")
    
    For Each wmiDiskDrive In wmiDiskDrives
        MsgBox "Disk drive Caption: " _
            & wmiDiskDrive.Caption _
            & VbNewLine & "DeviceID: " _
            & " (" & wmiDiskDrive.DeviceID & ")"
        MsgBox  "Serial number" _
                    & wmiDiskDrive.SerialNumber
        'Use the disk drive device id to
        ' find associated partition
        query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _
            & wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
        Set wmiDiskPartitions = wmiServices.ExecQuery(query)
    
        For Each wmiDiskPartition In wmiDiskPartitions
            'Use partition device id to find logical disk
            Set wmiLogicalDisks = wmiServices.ExecQuery _
                ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _
                 & wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
    
            For Each wmiLogicalDisk In wmiLogicalDisks
                MsgBox  "Drive letter associated" _
                    & " with disk drive = " _
                    & wmiDiskDrive.Caption _
                    & wmiDiskDrive.DeviceID _
                    & VbNewLine & " Partition = " _
                    & wmiDiskPartition.DeviceID _
                    & VbNewLine & " is " _
                    & wmiLogicalDisk.DeviceID
    
            Next
        Next
    Next
    It works perfectly in windows 8. But when I test in windows XP pc I got error while getting serial number i.e wmiDiskDrive.SerialNumber . All other objects are properly working.

    Then I found that this property is not available in windows XP,windows server 2003 etc. Now from above code I can get harddisk model number and the partitions in it,but I want serial number.

    So how I can get hard disk serial number and their partitions( should work in all windows OS)? Any idea?

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,528

    Re: Get serial number of all hard disks and partitions in it

    This should give you the Serial Number of the C drive....use other code determine which drives are available, and loop through it.
    Let me know if this works for what you want (as far as the SN).
    Code:
    Private Sub Command1_Click()
        Dim sn As String
       sn = GetSerialNumber("C:\")
       MsgBox sn
    End Sub
    Function GetSerialNumber(strDrive As String) As Long
        Dim lng1 As Long
        Dim fso As New FileSystemObject
        Dim drv As Drive
        Set drv = fso.GetDrive(fso.GetDriveName(strDrive))
        GetSerialNumber = drv.SerialNumber
        Set drv = Nothing
        Set fso = Nothing
    End Function

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,528

    Re: Get serial number of all hard disks and partitions in it

    Here is a better example....will find all drives and give you some information, including Serial Number (click on he Listbox to see specifics for each drive.
    Code:
     Option Explicit
          Dim fso As New FileSystemObject
          Dim fsoDrives As Drives
          Dim fsoDrive As Drive
          Private Sub Form_Load()
             Label1.AutoSize = True
             Command1.Caption = "List All Drives"
             List1.Enabled = False
          End Sub
          Private Sub Command1_Click()
             Dim sDrive As String
             Dim sDriveType As String
             Set fsoDrives = fso.Drives
             List1.Enabled = True
             For Each fsoDrive In fsoDrives
                sDrive = "Drive " & fsoDrive.DriveLetter & ": "
                Select Case fsoDrive.DriveType
                   Case 0: sDriveType = "Unknown"
                   Case 1: sDriveType = "Removable Drive"
                   Case 2: sDriveType = "Fixed Disk"
                   Case 3: sDriveType = "Remote Disk"
                   Case 4: sDriveType = "CDROM Drive"
                   Case 5: sDriveType = "RAM Disk"
                End Select
                sDrive = sDrive & sDriveType
                List1.AddItem (sDrive)
             Next
             Set fsoDrives = Nothing
          End Sub
          Private Sub List1_Click()
             Dim sDriveSpec As String
             Dim sSelDrive As String
             sSelDrive = List1.List(List1.ListIndex)
             sSelDrive = Mid(sSelDrive, 7, 1)
             Set fsoDrive = fso.GetDrive(sSelDrive)
             With fsoDrive
                If .IsReady = True Then
                   sDriveSpec = "Drive " & .DriveLetter & _
                               " Specifications" & vbLf
                   sDriveSpec = sDriveSpec & "Free Space: " & _
                                  .FreeSpace & " bytes" & vbLf
                   sDriveSpec = sDriveSpec & "File System: " & _
                                  .FileSystem & vbLf
                   sDriveSpec = sDriveSpec & "Serial Number: " & _
                                  .SerialNumber & vbLf
                   sDriveSpec = sDriveSpec & "Total Size: " & _
                                  .TotalSize & " bytes" & vbLf
                   sDriveSpec = sDriveSpec & "Volume Name: " & _
                                  .VolumeName
                   Label1.Caption = sDriveSpec
                Else
                   MsgBox ("Drive Not Ready")
                End If
             End With
             Set fsoDrive = Nothing
          End Sub

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,528

    Re: Get serial number of all hard disks and partitions in it

    Or you can use THIS with a filelistbox to get the drives:
    Code:
        Dim intDrive As Integer
        
        With Drive1
            For intDrive = 0 To .ListCount - 1
                Print .List(intDrive)
            Next
        End With

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by SamOscarBrown View Post
    Here is a better example....will find all drives and give you some information, including Serial Number (click on he Listbox to see specifics for each drive.
    Code:
     Option Explicit
          Dim fso As New FileSystemObject
          Dim fsoDrives As Drives
          Dim fsoDrive As Drive
          Private Sub Form_Load()
             Label1.AutoSize = True
             Command1.Caption = "List All Drives"
             List1.Enabled = False
          End Sub
          Private Sub Command1_Click()
             Dim sDrive As String
             Dim sDriveType As String
             Set fsoDrives = fso.Drives
             List1.Enabled = True
             For Each fsoDrive In fsoDrives
                sDrive = "Drive " & fsoDrive.DriveLetter & ": "
                Select Case fsoDrive.DriveType
                   Case 0: sDriveType = "Unknown"
                   Case 1: sDriveType = "Removable Drive"
                   Case 2: sDriveType = "Fixed Disk"
                   Case 3: sDriveType = "Remote Disk"
                   Case 4: sDriveType = "CDROM Drive"
                   Case 5: sDriveType = "RAM Disk"
                End Select
                sDrive = sDrive & sDriveType
                List1.AddItem (sDrive)
             Next
             Set fsoDrives = Nothing
          End Sub
          Private Sub List1_Click()
             Dim sDriveSpec As String
             Dim sSelDrive As String
             sSelDrive = List1.List(List1.ListIndex)
             sSelDrive = Mid(sSelDrive, 7, 1)
             Set fsoDrive = fso.GetDrive(sSelDrive)
             With fsoDrive
                If .IsReady = True Then
                   sDriveSpec = "Drive " & .DriveLetter & _
                               " Specifications" & vbLf
                   sDriveSpec = sDriveSpec & "Free Space: " & _
                                  .FreeSpace & " bytes" & vbLf
                   sDriveSpec = sDriveSpec & "File System: " & _
                                  .FileSystem & vbLf
                   sDriveSpec = sDriveSpec & "Serial Number: " & _
                                  .SerialNumber & vbLf
                   sDriveSpec = sDriveSpec & "Total Size: " & _
                                  .TotalSize & " bytes" & vbLf
                   sDriveSpec = sDriveSpec & "Volume Name: " & _
                                  .VolumeName
                   Label1.Caption = sDriveSpec
                Else
                   MsgBox ("Drive Not Ready")
                End If
             End With
             Set fsoDrive = Nothing
          End Sub
    Thank you. But I didn't want the serial number of each partitions which is different(I have also mentioned in my question like I am not referring to volume serial number). I wanted the physical hard disks serial number which was given by manufacturer. Also I wanted to check the partitions in each harddisks. So can you please help me on this.
    Last edited by IT researcher; Nov 16th, 2014 at 11:36 PM.

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,528

    Re: Get serial number of all hard disks and partitions in it

    Guess I misread/misunderstood your post. No, that is all I have ever done/seen reference drive serial numbers. Sorry.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    This may not do everything you asked for, is not thoroughly debugged, will not work on Windows 95 (and perhaps not on any Win9x OS), has not been thoroughly tested on Windows XP, etc.

    But it does work at least on systems where I've thoroughly tested it (Windows Vista and later), and seems to at least partially work on Windows XP (USB flash drives not tested). That doesn't mean it will work on all Vista and later systems, since hard drive manufacturers do some screwy hardware serial number representation (sometimes hex digits of ASCII, sometimes ASCII, character pairs inverted).

    While the giant pachinko machine known as the heavyweight WMI Service (often disabled or removed from machines for security) probably has a larger rules database for decoding such things it is also known to miss things for some drives.

    See the comments, many systems will report SATA drives as ATA due to design limitations in Windows. Google ATAPortInfo.docx for details.

    Name:  sshot.png
Views: 2649
Size:  24.7 KB
    Attached Files Attached Files
    Last edited by dilettante; Nov 17th, 2014 at 01:23 PM.

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,609

    Re: Get serial number of all hard disks and partitions in it

    dilettante, that's a nice piece of code.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    Thanks. It is sort of cobbled together from various bits and pieces of old code and ported code written by others (credited in the comments) and with time I might get the glitches out.

    The major glitch seems to be USB hard drives, which I haven't had a lot of luck with.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Re: Get serial number of all hard disks and partitions in it

    Hi dilettante,

    Nice code .But the code given by you does not provide serial number in window XP. (I am not worried about win 95 etc , because I want it to work in windows XP and higher version)

    In the WMI code also I missed same. Any workaround to make it work in windows XP (at least in administrator user) ?

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,478

    Re: Get serial number of all hard disks and partitions in it

    I tried it here under XP. It threw 2 errors. Only returned a serial number for my raid mirrored drive. Did not return the info of either of the actual hard drives that are mirrored.
    Code:
    Error &H80047104 DeviceIoControl error 1
    Drive letter: "A"
    
    Drive letter: "C"
        BusType = 3 (ATA)
        DeviceType = 0 (Disk)
        ProductId = "WDC WD1002FAEX-00Z3A0"
        ProductRevision = "05.01D05"
        Removable = False
        SerialNumber = ""
        VendorId = ""
    
    Drive letter: "D"
        BusType = 3 (ATA)
        DeviceType = 0 (Disk)
        ProductId = "ST31000528AS"
        ProductRevision = "CC44"
        Removable = False
        SerialNumber = ""
        VendorId = ""
    
    Drive letter: "E"
        BusType = 2 (ATAPI)
        DeviceType = 5 (CDROM)
        ProductId = "ATAPI DVD A  DH24AAS"
        ProductRevision = "BP5A"
        Removable = True
        SerialNumber = ""
        VendorId = ""
    
    Drive letter: "F"
        BusType = 8 (RAID)
        DeviceType = 0 (Disk)
        ProductId = ""
        ProductRevision = "0000"
        Removable = False
        SerialNumber = "ARDI"
        VendorId = "DataM"
    
    Drive letter: "G"
        BusType = 3 (ATA)
        DeviceType = 0 (Disk)
        ProductId = "WDC WD1002FAEX-00Z3A0"
        ProductRevision = "05.01D05"
        Removable = False
        SerialNumber = ""
        VendorId = ""
    
    Error &H80047104 DeviceIoControl error 21
    Drive letter: "H"
    
    Drive letter: "I"
        BusType = 1 (SCSI)
        DeviceType = 5 (CDROM)
        ProductId = "KPR103W"
        ProductRevision = "2.0B"
        Removable = True
        SerialNumber = ""
        VendorId = "PB2847W"

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    As I said it has warts. Feel free to point me to another example that works! I could use it myself. This is tricky stuff though, Windows was not designed to offer it up to applications easily.

    A lot of criticism for a free code handout.


    There are other routes that can be taken that require priviledge elevation, and they may work better but I don't have any working code to share.

    WMI is useless because it may be disabled or not installed at all.

    The code attached above was designed with the goal of not requiring elevation so it might be used in normal applications. Those would typically only look at the system drive or at the "running from" USB flash drive in the case of a portable application.

    Seems to work fine here on XP for the system drive. I haven't tested USB flash drives on XP.

    I don't have any floppy drives or RAID drive configurations so those have never been tested (and thus never debugged).


    Hopefully somebody can help modify this to do a better job. I'd like USB hard drive serial numbers myself, but I get back an opaque string of hex digits when I try it.
    Last edited by dilettante; Nov 18th, 2014 at 10:40 AM.

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    As for RAID drives, you might get further attacking this by enumerating physical devices and using the \\.\PhysicalDrive0, \\.\PhysicalDrive1, etc. format to interrogate them.

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,478

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by dilettante View Post
    As I said it has warts. Feel free to point me to another example that works! I could use it myself. This is tricky stuff though, Windows was not designed to offer it up to applications easily.

    A lot of criticism for a free code handout.
    I wasn't trying to criticize, just giving some feedback as to how it preformed on my XP box.

    A useful piece of code. I may look into it deeper when I have time.

  15. #15
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    Yeah, it seems to be a pretty tough thing to accomplish in general. I'm sure that's why WMI often fails to return anything or appears to return "junk."

    For local (ATA, SATA) hard drives that are "ready" (not RAID members) you can get back either ASCII with the characters inverted in pairs with leading or trailing spaces or even ASCII hex digits of ASCII values with the characters inverted in pairs with leading or trailing spaces:

    "WD-12345" as "************DW1-3254" where "*" is a space

    "WD-12345" as "2020202020202020202020204457312D33323534"

    USB drives always give back Unicode hex digits. The values from USB hard drives are garbage (or obfuscated), as confirmed by disk vendor utilities that can report the real serial number. I'm suspicious of the values for flash drives but the available "lore" suggests this is correct.

    Example:

    Code:
    Drive letter: "G"
        BusType = 7 (USB)
        DeviceType = 0 (Disk)
        ProductId = "Cruzer Blade"
        ProductRevision = "1.00"
        Removable = True
        SerialNumber = "20044323010C61639088"
        VendorId = "SanDisk"
    And optical media (CDs, DVDs)? Getting the media serial numbers of these looks like a nightmare. I can't tell if it is even possible for floppies.

  16. #16
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,609

    Re: Get serial number of all hard disks and partitions in it

    Awww, you mean my 128k 8 inch floppies don't have serial numbers on them?
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  17. #17
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    No, as far as I know there were no rigid standards for floppy disk encoding so there wouldn't be a way to have a media serial number. But wow, floppy disks! Reminded me of the days when some drives required hard sectored media with extra timing holes.

    Of course I still use other obsolete formats such as SmartMedia and xD cards. My main desktop and laptop have built in "readers" for those and other card formats. Most people today stick to SD or microSD cards.

    I still have a number of SuperDisk drives, though none in use. I ought to take one of the IDE units and put it into this machine, then I could use the LS-120 disks as well as the blank 3 1/2" floppies I still have around here.

  18. #18
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,609

    Re: Get serial number of all hard disks and partitions in it

    *laughs*

    Yeah, I almost mentioned hard-sector floppies, but I think those came about a bit later (after the 8" floppies). The only ones I ever saw were of the 5.25" variety.

    And yeah, I knew they didn't have serial numbers. I was just being silly.

    Actually, it'll surprise me a bit even if all USB sticks have serial numbers. They'd better be long if they do, as they have to have made a gazillion of those things.

    Say OP, why do you need it anyway? If it's writable media, why not just put your own identifying file out there. Need help making a thousand digit random number to stick in the file? Easy peasy. And if you need to keep track of things, just save those random numbers in some database and check it against the media that's "plugged in".

    IDK, it just seems like using a serial number is a bit of a strange way to keep track of things. But who am I to suggest that someone's idea should be re-thought?

    I hope you get it going.

    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by Elroy View Post
    Actually, it'll surprise me a bit even if all USB sticks have serial numbers. They'd better be long if they do, as they have to have made a gazillion of those things.
    Actually some vendors didn't in the past and it caused problems.

    What characters or bytes are valid in a USB serial number?

    If the device has a serial number, the serial number must uniquely identify each instance of the same device.

    For example, if two device descriptors have identical values for the idVendor, idProduct, and bcdDevice fields, the iSerialNumber field must be different, to distinguish one device from the other.
    This was why some vendor's USB flash drives caused users problems such as seemingly failing when two or more were plugged in. If they wanted the poor saps to buy and use more than one they needed unique serial numbers or else quite a few devices would get returned as bad when Windows couldn't use them at the same time.

    Even with no serial number one of the other 3 items must be unique, but the serial number is the preferred unique value.

    A program checking for this needs to at least take Vendor, Product, and SerialNumber into account. The bcdDevice value may as well be considered too (a "device release number in binary-coded decimal") to determine uniqueness.

  20. #20
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by Elroy View Post
    Actually, it'll surprise me a bit even if all USB sticks have serial numbers. They'd better be long if they do, as they have to have made a gazillion of those things.

    Say OP, why do you need it anyway? If it's writable media, why not just put your own identifying file out there. Need help making a thousand digit random number to stick in the file? Easy peasy. And if you need to keep track of things, just save those random numbers in some database and check it against the media that's "plugged in".
    The OP wasn't asking about flash media, I drove things off-track with that.

    He seems to be doing some admin chore related only to hard drives as far as I can tell. Not really a normal VB usage, more of a box jockey task a WMI script would be used for.

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by dilettante View Post
    The OP wasn't asking about flash media, I drove things off-track with that.

    He seems to be doing some admin chore related only to hard drives as far as I can tell. Not really a normal VB usage, more of a box jockey task a WMI script would be used for.
    Yes. Flash media are not required. Only hard disks and it would be better if i get external hard disks too.

    Your code works perfectly in windows 7 and 8 both user and admin user . But in Windows XP PC serial numbers are not retrieved. I had tested it in about three XP pc and all didn't return serial number.

    Code:
    Drive letter: "C"
        BusType = 3 (ATA)
        DeviceType = 0 (Disk)
        ProductId = "WDC WD3200AVJS-63B6A0"
        ProductRevision = "01.03A02"
        Removable = False
        SerialNumber = ""
        VendorId = ""
    
    Drive letter: "D"
        BusType = 3 (ATA)
        DeviceType = 0 (Disk)
        ProductId = "WDC WD3200AVJS-63B6A0"
        ProductRevision = "01.03A02"
        Removable = False
        SerialNumber = ""
        VendorId = ""
    
    Drive letter: "E"
        BusType = 3 (ATA)
        DeviceType = 0 (Disk)
        ProductId = "WDC WD3200AVJS-63B6A0"
        ProductRevision = "01.03A02"
        Removable = False
        SerialNumber = ""
        VendorId = ""
    
    Drive letter: "F"
        BusType = 3 (ATA)
        DeviceType = 0 (Disk)
        ProductId = "WDC WD3200AVJS-63B6A0"
        ProductRevision = "01.03A02"
        Removable = False
        SerialNumber = ""
        VendorId = ""
    Last edited by IT researcher; Nov 19th, 2014 at 01:01 AM.

  22. #22
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,609

    Re: Get serial number of all hard disks and partitions in it

    Well gosh dilettante, since you're admitting to taking things off track, I suppose I'll admit to egging it on.

    These forums are just fun for me, but I do understand that some are actually trying to get some work done. And I have actually managed to learn a few things.

    And again, I'm a bit out of my area of expertise (finding out hardware serial numbers from API calls), but I am a bit surprised that it doesn't work on XP. How's it failing, researcher? Is it coming up with some "library not found" message? Or is it just silently failing and reporting a bunch of blanks?

    The "library not found" would make sense, as there may be DLLs on Vista, etc., that just aren't on XP. Or, if there's a non-existing entry point for a DLL (because it's an older version). Not sure, but I believe that should produce an error as well. To silently fail though would be curious.

    I had another idea, but after staring at the code I don't think there's anyway possible that it'd work. I was thinking that you could possibly copy some DLLs from a Win7 machine and put them on WinXP, but it seems that it's the kernel32.dll that's doing the work. That's a pretty core part of the Windows OS, and swapping an older version for a newer one would quite possibly bring down the whole system. If it's not working on WinXP, it seems like you may be SOL.

    But best of luck anyway,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  23. #23
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    I don't have any operational Windows XP machines right now, though there is an old one I might get around to booting up for a test.

    I did test on a Windows XP SP3 VM running in MS Virtual PC and it had no problem reporting a serial number for the virtual drive with the C:\ system partition on it. Hard to plug flash media into one so I couldn't try USB flash drive serials.

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by Elroy View Post
    How's it failing, researcher? Is it coming up with some "library not found" message? Or is it just silently failing and reporting a bunch of blanks?
    Yes. it does not give error , but returns blank.

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by dilettante View Post
    I don't have any operational Windows XP machines right now, though there is an old one I might get around to booting up for a test.

    I did test on a Windows XP SP3 VM running in MS Virtual PC and it had no problem reporting a serial number for the virtual drive with the C:\ system partition on it. Hard to plug flash media into one so I couldn't try USB flash drive serials.
    Just now i tested on another Windows XP professional service pack 3 and serial number returned as blank. In home edition also same problem.
    Where as DISKID32 returns proper serial number. But it lacks partition information.

  26. #26
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    If you go look at their site it says:

    How does DiskId32 work?

    • Windows 95 / 98 / ME: Uses a VXD for talking directly to the IDE hard drives
    • Windows 8 / 7 / Vista / Windows NT / 2000 / XP (administrator rights): Uses the PhysicalDrive interface
    • Windows NT / 2000 / XP (user rights only): Uses the SCSI back door to access the IDE hard drives (does not work with Windows Server 2003 or Vista)
    • Windows 8 / 7 / Vista / Windows XP (guest rights only): Uses the PhysicalDrive interface (has occasional problems on Windows XP, Windows 2003 Server and Vista)

    DiskId32 only works with IDE / PATA / SATA drives for now. DiskId32 does not work with RAID controller cards (like Promise).

    DiskId32 does not work with network drives. All queried hard drives must be physically connected to the PC.
    There is no "PhysicalDrive interface" so I assume they mean the "Physical Disk" form of the CreateFile() function call.

    My DriveInfo class does the very same thing (retrieving the STORAGE_DEVICE_DESCRIPTOR data) aside from using the "Volume" format for calling CreateFile(), since my purpose was to get "logical drive" information by drive letter. This was done because it makes far more sense for applications simply trying to validate product registration, though it isn't as useful if you are trying to make an admin tool.

    I think I covered this earlier:

    You could modify the class to use Physical Disk calls easily enough, probably removing the use of the UsbFlashSerial class which can't use them anyway. Then your calling program could enumerate the physical disk drives (instead of the drive letters) and use the class on each one.

    That still won't get you partition info. For that matter my DriveInfo class as-is doesn't do that either, it just allows use on partitions with drive letters and can't "see" other kinds of partitions.


    What you want seems to be something different from what either WinSim's DiskId32 or my DriveInfo class do. I knew this from your original post, and hesitated replying at all for that reason. However I decided my code might serve as a starting point for you.

    Now you just need to do a little work yourself.
    Last edited by dilettante; Nov 20th, 2014 at 01:50 AM.

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by dilettante View Post
    If you go look at their site it says:



    There is no "PhysicalDrive interface" so I assume they mean the "Physical Disk" form of the CreateFile() function call.

    My DriveInfo class does the very same thing (retrieving the STORAGE_DEVICE_DESCRIPTOR data) aside from using the "Volume" format for calling CreateFile(), since my purpose was to get "logical drive" information by drive letter. This was done because it makes far more sense for applications simply trying to validate product registration, though it isn't as useful if you are trying to make an admin tool.

    I think I covered this earlier:

    You could modify the class to use Physical Disk calls easily enough, probably removing the use of the UsbFlashSerial class which can't use them anyway. Then your calling program could enumerate the physical disk drives (instead of the drive letters) and use the class on each one.

    That still won't get you partition info. For that matter my DriveInfo class as-is doesn't do that either, it just allows use on partitions with drive letters and can't "see" other kinds of partitions.


    What you want seems to be something different from what either WinSim's DiskId32 or my DriveInfo class do. I knew this from your original post, and hesitated replying at all for that reason. However I decided my code might serve as a starting point for you.

    Now you just need to do a little work yourself.
    Ok.
    As your solution works well on all other than XP so I can use it for vista and above.
    But for XP i have to use DISKID32 (which worked for me in all XP pc to get serial number) but it didn't have option of getting partition. So can I have any chance of getting partition information from the DISKID32 code by modifying it anyway? Please guide me.
    Thank you

  28. #28
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,157

    Re: Get serial number of all hard disks and partitions in it

    As they mention for DiskId32, to get the serial number on XP w/o admin rights you might try the "SCSI backdoor" (searches should turn up info on that technique).

    Then perhaps look at articles and code such as Get a list of physical disks and the partitions on them in VB.NET the easy way. You might try to explore the sample code or else just go look up the API functions and work it out yourself from there.

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Re: Get serial number of all hard disks and partitions in it

    Quote Originally Posted by dilettante View Post
    As they mention for DiskId32, to get the serial number on XP w/o admin rights you might try the "SCSI backdoor" (searches should turn up info on that technique).

    Then perhaps look at articles and code such as Get a list of physical disks and the partitions on them in VB.NET the easy way. You might try to explore the sample code or else just go look up the API functions and work it out yourself from there.
    I found a article here which gets serial number in Windows XP but only if user is administrative.
    I have modified this code and passed the drive letter to createfile method as you did.
    It works properly now. but my code is not that proper. In the code the procedure SmartCheckEnabled is used and i think drvNumber passed to it should be 0 in case only one harddisk present and so on. But i am passing index from getdrives procedure to it which is wrong i guess.(in the original code they passed drvNumber based on harddisk. So please suggest me how can I correct it? Is there any other problem in my code.Please have a look.
    Attached Files Attached Files

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width