Menu

How to get disk serial number (win32)?

2004-08-22
2012-09-26
  • Nobody/Anonymous

    Hi,

    how to get a disk serial number with DEV-CPP (win32)?

    I've seen "asm" instructions (int 21h) but they are incomplete and it seems DEV-CPP does not allow directly interrupts (win32).

    I've seen old discussions about a "bios.h" library that would not be anymore supported (win32, too bad) and which used to retreive many system info.

    What is the status today with "API" to system info?
    More specifically what is the simplest way to get a disk serial number?

    Thanks Claude

     
    • Anonymous

      Anonymous - 2004-08-22
       
      • qWake

        qWake - 2004-08-22

        Note that this gives the volume ID, not the hard drive serial ID.  The volume ID changes if the drive is re-formatted.

        Getting the serial number of the hard drive is more complicated.  Google on SMART to get some tips for SMART-enabled drives (most modern drives are).  There are a few programs like smartapp.exe that will report the drive ID and other data, and the C source code is available.  This will not work on older drives that don't support SMART, and for those there is no guaranteed way to get the number since not all manufacturers store it at the same location.  Also Google on ioctl for more hints.

        qWake

         
        • Anonymous

          Anonymous - 2004-08-22

          If the drive is formatted, the software that needs to know the ID will have to be reinstalled, so it'll never know the difference! ;-)

          More seriously; you are right, but maybe this is adequate for the OP's purposes. The volume ID for example is what tools such as FlexLM use to generate license keys locked to a machine.

          Clifford

           
    • Nobody/Anonymous

      LOL, I love it! int 13 this, interrupt blah, bios that.

      <MSDN link> he he ;)

      Kip

       
      • Anonymous

        Anonymous - 2004-08-22

        What I find extrodinary is that nine years after Windows 95 was released (and longer since NT and the Win32 API itself), there are people still attempting DOS system calls, did no one tell them the world was leaving them behind?

        That is not to say that arcane knowledge is not sometimes useful, but so is keeping up with the times.

        Clifford

         
    • Nobody/Anonymous

      Hmm, I am not sure anymore. I have looked through my asm book and I don't think there is a standard BIOS method to aquire this. Maybe it is stuffed in the hard drive data area at 75h.

      Kip

       
    • Nobody/Anonymous

      #define _WIN32_WINNT 0x0501          // need this for some reason, dont know why
      #define BUFSIZE            MAX_PATH  // but MSDN says you need it, and it doesnt work without
      #define FILESYSNAMEBUFSIZE MAX_PATH

      #include <windows.h>
      #include <stdio.h>

      // Part of this code stolen from d MSDN sample
      BOOL ProcessVolume (HANDLE hVol, TCHAR *Buf, int iBufSize)
      {
         BOOL bFlag;           // generic results flag for return
         HANDLE hPt;           // handle for mount point scan
         TCHAR PtBuf[BUFSIZE]; // string buffer for mount points
         DWORD dwSysFlags;     // flags that describe the file system
         TCHAR FileSysNameBuf[FILESYSNAMEBUFSIZE];
        
         DWORD serial = 0;

         printf ("Volume found is \&quot;%s\&quot;.\n", Buf);

         GetVolumeInformation( Buf, NULL, 0, &serial, NULL,
                               &dwSysFlags, FileSysNameBuf,
                               FILESYSNAMEBUFSIZE);

         UINT type = GetDriveType(Buf);     // only if youre interested in types too

         printf ("serial: %d  -- %x    type= %d\n\n", serial, serial, type);

         bFlag = FindNextVolume(
                   hVol,    // handle to scan being conducted
                   Buf,     // pointer to output
                   iBufSize // size of output buffer
                 );

         return (bFlag);
      }

      int main(void)
      {
         TCHAR buf[BUFSIZE];      // buffer for unique volume identifiers
         HANDLE hVol;             // handle for the volume scan
         BOOL bFlag;              // generic results flag

         hVol = FindFirstVolume (buf, BUFSIZE );

         if (hVol == INVALID_HANDLE_VALUE)
         {
            printf("No volumes found!\n");
            return(-1);
         }

         // We have a volume; process it.
         bFlag = ProcessVolume (hVol, buf, BUFSIZE); // handle returned is needed for next

         // Do while we have volumes to process.
         while (bFlag)
         {
            bFlag = ProcessVolume(hVol, buf, BUFSIZE);
         }
         bFlag = FindVolumeClose(hVol);

      /*   if you want to know what "type" actually means
      printf("\n\n\nDRIVE_UNKNOWN\t%d\n",  DRIVE_UNKNOWN  );
      printf("DRV_NO_ROOT_DIR\t%d\n",  DRIVE_NO_ROOT_DIR  );
      printf("DRIVE_REMOVABLE\t%d\n",  DRIVE_REMOVABLE  );
      printf("DRIVE_FIXED\t%d\n",  DRIVE_FIXED  );
      printf("DRIVE_REMOTE\t%d\n",  DRIVE_REMOTE  );
      printf("DRIVE_CDROM\t%d\n",  DRIVE_CDROM  );
      printf("DRIVE_RAMDISK\t%d\n",  DRIVE_RAMDISK  );     */

         return (0);
      }

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.