2

I am interested in CD identification.

My Question:

Is there a serial number that can be retrieved programmatically?

Edit (Resolved):

  1. VB version
  2. Delphi version
Community
  • 1
  • 1
menjaraz
  • 7,551
  • 4
  • 41
  • 81

2 Answers2

2

Try this code in VB

Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Form_Load()
    Dim Serial As Long
    'Get the volume information
    GetVolumeInformation "d:\", vbNullString, 255, Serial, 0, 0, vbNullString, 255

    MsgBox Hex(Serial)
End Sub 

This should serve as a proof of concept for you. You can adapt this to your language of choice.

Taken from here: VB Forums

JimmyPena
  • 8,694
  • 6
  • 43
  • 64
Andrei G
  • 1,590
  • 8
  • 13
  • Thank you for answering. I just want to ascertain that the `Serial` retrieved is OS indepented, is that so or it just a specific hash computed by Windows ? – menjaraz Feb 27 '12 at 08:45
  • The CD-ROMs do actually have a Serial number. It is OS independent – Andrei G Feb 27 '12 at 08:46
  • Thank you again. I accept your answer and I will try to do a Delphi port and post it later. I add a [tag:language-agnostic] tag to the Q. Hopefully other languages implementation (answers) will be posted here. – menjaraz Feb 27 '12 at 08:51
  • bigresource.com is some kind of auto-generated doorway scraper site that just redirects you while showing ads. If you can, you should post a link to the "real" content. – JimmyPena Jul 26 '12 at 14:56
1

Windows.GetVolumeInformation Syntax

  GetVolumeInformation(
    lpRootPathName: PChar; {the path to the root directory}
    lpVolumeNameBuffer: PChar; {the buffer receiving the volume name}
    nVolumeNameSize: DWORD; {the maximum size of the buffer}
    lpVolumeSerialNumber: PDWORD; {a pointer to the volume serial number}
    var lpMaximumComponentLength: DWORD; {maximum file component name}
    var lpFileSystemFlags: DWORD; {file system flags}
    lpFileSystemNameBuffer: PChar; {the buffer receiving the file system name}
    nFileSystemNameSize: DWORD {the maximum size of the file system name}
  ): BOOL; {returns TRUE or FALSE}

Delphi port (slightly adapted from Andrei G's post)

GetCDROMSerial snippet:

  function GetCDROMSerial(AVolName: Char ) : DWord;
  var
   Dummy1, Dummy2 : DWord;
  begin
   GetVolumeInformation(
     PChar( AVolName+':' ),
     nil,
     0,
     @Result,
     Dummy1,
     Dummy2,
     nil,
     0
     );
  end;

Usage sample:

  ShowMessage(Format('%X', [GetCDROMSerial('F')]));
Community
  • 1
  • 1
menjaraz
  • 7,551
  • 4
  • 41
  • 81