#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    2
    Rep Power
    0

    retrieve disk serial number using clusDisk or similar


    Can anyone out there give some pointers on how to use clusDisk or similar to retrieve the serial number of a hard disk
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    2
    Rep Power
    0
    Found a solution
    Code:
    #include "stdafx.h"
    #include <windows.h>
    
    int main(int argc, char* argv[])
    {
      char szRootPathName[] = "f:\\";
      char szVolumeNameBuffer[128] = {0};
      DWORD lpVolumeSerialNumber = 0;
      DWORD lpMaximumComponentLength = 0;
      DWORD lpFileSystemFlags = 0;
      char szFileSystemNameBuffer[128] = {0};
    
      int iRetVal = GetVolumeInformation (szRootPathName,
        szVolumeNameBuffer,
        sizeof(szVolumeNameBuffer),
        &lpVolumeSerialNumber,
        &lpMaximumComponentLength,
        &lpFileSystemFlags,
        szFileSystemNameBuffer,
        sizeof(szFileSystemNameBuffer));
    
      if(iRetVal)
      {
        printf("Serial number of %s is %d",szRootPathName,lpVolumeSerialNumber);
      }
      else
      {
        printf("could not retrieve data for drive %s", szRootPathName);
      }
      return 0;
    }
    this is a slightly modified version of code found in the MSDN
    Last edited by snuv; January 29th, 2003 at 01:28 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    9
    Rep Power
    0
    I got 0 as serial number ?????
  6. #4
  7. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    I am not getting it to work either. I am looking at http://msdn.microsoft.com/library/de...unt_points.asp and it is very frustrating when MS's own examples won't compile. Bill better hope he never meets me in a dark alley!

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  8. #5
  9. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    I found some interesting things. If you print the serial number as an integer, it comes out negative, which appears to be junk. If you haven't assigned a name to the drive, it comes out blank. I have no idea how to find out independantly what the serial number is, so I don't know about that, but I do know that when I changed the name of the drive, it changed when I ran the program.

    This is the code I ran:

    Code:
    #include <stdio.h>
    #include <windows.h>
    
    #define BUFLEN 1024
    
    int main(){
        char szRootPathName[] = "f:\\";
        char szVolumeNameBuffer[BUFLEN] = {0};
        DWORD lpVolumeSerialNumber = 0;
        DWORD lpMaximumComponentLength = 0;
        DWORD lpFileSystemFlags = 0;
        char szFileSystemNameBuffer[BUFLEN] = {0};
    
        bool iRetVal = GetVolumeInformation (szRootPathName,
                                            szVolumeNameBuffer,
                                            BUFLEN,
                                            &lpVolumeSerialNumber,
                                            &lpMaximumComponentLength,
                                            &lpFileSystemFlags,
                                            szFileSystemNameBuffer,
                                            BUFLEN);
    
        if(iRetVal){
            printf("Serial number of %s is %X\n",szRootPathName,lpVolumeSerialNumber);
            printf("szVolumeNameBuffer: %s\n",szVolumeNameBuffer);
            printf("szFileSystemNameBuffer: %s\n",szFileSystemNameBuffer);
        }else{
            printf("could not retrieve data for drive %s.  GetLastError: %d\n", szRootPathName, GetLastError());
        }
        return 0;
    }

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo