[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Real serial number of cd ( not the volume number )

Hi, I copy the installation of my software to a cd-rom. Then, I create an image of this cd, and burn this image in another cd. So, the 2 cds has the same volume number. I would like to identify each disc solely, because anyone can create an image of the original disk and distribute this cd, or something else. So, I would like to recognize when the software was copied to another cd, like a manufacturer's number, so, if it is a copy of the original cd, it has another manufacturer number.

Thanks.
0
emu10k1
Asked:
emu10k1
  • 5
  • 5
  • 2
  • +2
1 Solution
 
BobcsiCommented:
Windows creates a "Virtual Series Number" for Audio CDs. You can use the following code to get the VSN of an audio CD:

type
  TNumbBase = 1..36;

function NumbToStr(Numb: LongInt; Base: TNumbBase): string;
const
  NumbDigits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
begin
  Result := EmptyStr;
  while Numb > 0 do
  begin
    Result := NumbDigits[(Numb mod Base) + 1] + Result;
    Numb := Numb div Base;
  end;
  if Result = EmptyStr then
    Result := '0';
end;

function GetCDID(Drive: string): string;
var
  Serial: DWord;
  T: Cardinal;
begin
  if GetVolumeInformation(PChar(Drive), nil, 0, @Serial, T, T, nil, 0) then
    Result := NumbToStr(Serial, 16)
  else
    Result := EmptyStr;
end;

Drive should be the name of the root directory of your CD drive. Use it like

ShowMessage(GetCDID('I:\'));

or

ShowMessage(GetCDID('\\Computer2\\CDDrive\'));


Solve 2:

You have to use the API-call GetVolumeInformation. But first, you have to implement it correctly:


function GetVolumeInformation(lpRootPathName: PAnsiChar; lpVolumeNameBuffer: PAnsiChar; nVolumeNameSize: DWORD; var lpVolumeSerialNumber, lpMaximumComponentLength,
lpFileSystemFlags: DWORD; lpFileSystemNameBuffer: PAnsiChar; nFileSystemNameSize: DWORD): bool; stdcall; external kernel32 name 'GetVolumeInformationA';


In your application:


function GetCDId: string;
var
  root: string;
  VolumeNameBuffer, FileSystemNameBuffer: PChar;
  VolumeSerialNumber, FileSystemFlags, MaximumComponentLength: LongInt;

  function Int2Hex(number: LongInt): string;
  var
    i: LongInt;
    s: string;
  begin
    s := '';
    i := 0;
    while number > 0 do
    begin
      i := number mod 16;
      case i of
        0..9: s := IntToStr(i) + s;
        10: s := 'A' + s;
        11: s := 'B' + s;
        12: s := 'C' + s;
        13: s := 'D' + s;
        14: s := 'E' + s;
        15: s := 'F' + s;
      end;
      number := number - i * 16;
    end;
    Result := s;
  end;

begin
  root := 'x:\'; {where X is the drive letter of your CD drive}
  VolumeNameBuffer := StrAlloc(256);
  FileSystemNameBuffer := StrAlloc(256);
  if GetVolumeInformation(PChar(root), VolumeNameBuffer, 255, VolumeSerialNumber,
    MaximumComponentLength, FileSystemFlags, FileSystemNameBuffer, 255) then
    Result := Int2Hex(VolumeSerialNumber);
else
  Result := '';
end;

Bobcsi
0
 
tobjectpascalCommented:
Using GetVolumeInformation is NOT the way to go, since this way you'll get different serial numbers for win9x and winNT for the same CD, don't ask me why...

I'm using the following code, which is a bit similar to Motaz' code, however, it doesn't need that MediaPlayer, furthermore it works also if you have more than one CD drive (I don't see how you could ask the serial number for specific cd drives with Motaz' code).

function GetCDSerialNo(drive: char) : cardinal;
var mo : TMCI_OPEN_PARMS;
mp : TMCI_INFO_PARMS;
mg : TMCI_GENERIC_PARMS;
s1 : string;
arrCh : array [0..255] of char;
begin
result := 0;
s1 := drive + ':';
ZeroMemory(@mo, sizeOf(mo));
ZeroMemory(@mp, sizeOf(mp));
ZeroMemory(@mg, sizeOf(mg));
mo.lpstrDeviceType := pchar(MCI_DEVTYPE_CD_AUDIO);
mo.lpstrElementName := pchar(s1);
mp.lpstrReturn := arrCh;
mp.dwRetSize := sizeOf(arrCh) - 1;
if mciSendCommand(0, MCI_OPEN,
MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE or
MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_WAIT,
cardinal(@mo)) = 0 then
try
if mciSendCommand(mo.wDeviceID, MCI_INFO, MCI_INFO_MEDIA_IDENTITY, cardinal(@mp)) = 0 then
result := cardinal(StrToIntDef(arrCh, 0));
finally mciSendCommand(mo.wDeviceID, MCI_CLOSE, 0, cardinal(@mg)) end;
end;

0
 
tobjectpascalCommented:
uses MMsystem;

procedure TForm1.Button1Click(Sender: TObject);
Var
 drv: Char;
begin
 Drv:='D'; //whatever
 Edit1.Text:=IntToStr(GetCDSerialNo(Drv));
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
emu10k1Author Commented:
Bobcsi: I try the first solve that you say... and it didn't work, it get the same number for the two cds, so, it didn't identify each cd, it shows me the volume number, that is the same if the first cd is a image of the second cd.

and your second solve, it freeze when i call GetCDId. And I change  VolumeSerialNumber, FileSystemFlags, MaximumComponentLength: LongInt; for VolumeSerialNumber, FileSystemFlags, MaximumComponentLength: Cardinal; because it shows me "Types of actual and formal var parameters must be identical" .

emu10k1
0
 
emu10k1Author Commented:
tobjectpascal: it shows me the same number in the two cds. This code get the volume number, and the volume number is the same if the first cd is an image of the second cd. I want the manufacturer number, a number that is unique, so, this number never will be the same of another cd.

Thanks, and please help if you know how to solve this problem.

emu10k1
0
 
tobjectpascalCommented:
if it's an identical clone which is what an image is, of course it will be identical, otherwise the program would not run if one of the security measures is checking the serial of the CD.
0
 
emu10k1Author Commented:
your code shows me the number 3579 in two cds(original and clone). so, if anyone burn an image, the program will run normally.
0
 
tobjectpascalCommented:
well if the second disk showed ANY OTHER serial number other than the one you cloned, it would NOT BE A CLONE now would it!
0
 
emu10k1Author Commented:
yeah... I would like to the second disk show any other serial number, not the same serial of the first disk... but this didn't happen... it shows me the same serial number for the first and second disk...
0
 
tobjectpascalCommented:
and third and fourth and fith, i don't think you quite understand the word "clone" if two frogs looked identical expect one had red eyes and the other had blue eyes, it would no longer be a clone, if it was a clone the serial number included would be identical otherwise it would not be a clone, what you're asking for is impossible, all a CD is plastic which gets grooves cut into it, 0 or 1 right, from start to finish it would be exactly the same as your other CD, the serial you're refering to is not something that can be extracted, it sits in the rim where the laser does not go, that's the manufacture serial, and as far as i am aware you can not get it.
0
 
ginsonicCommented:
MessageDlg(
  'Serial number: ' +
  Format( '%X', [ GetDiskVolSerialID( 'E' ) ] ),
  mtInformation, [mbOk], 0 );
0
 
emu10k1Author Commented:
ginsonic: where are declared this function "GetDiskVolSerialID" ?
0
 
sad_manCommented:
here is some code of mine
u can use this

uses MMSystem, MPlayer;

procedure TForm1.Button1Click(Sender: TObject);
var
mp : TMediaPlayer;
msp : TMCI_INFO_PARMS;
MediaString : array[0..255] of char;
ret : longint;

begin
mp := TMediaPlayer.Create(nil);
mp.Visible := false;
mp.Parent := Application.MainForm;
mp.Shareable := true;
mp.DeviceType := dtCDAudio;
mp.FileName := 'D:';
mp.Open;
Application.ProcessMessages;
FillChar(MediaString, sizeof(MediaString), #0);
FillChar(msp, sizeof(msp), #0);
msp.lpstrReturn := @MediaString;
msp.dwRetSize := 255;
ret := mciSendCommand(Mp.DeviceId,
MCI_INFO,
MCI_INFO_MEDIA_IDENTITY,
longint(@msp));
if Ret <> 0 then
begin
MciGetErrorString(ret, @MediaString, sizeof(MediaString));
Memo1.Lines.Add(StrPas(MediaString));
end
else
Memo1.Lines.Add(StrPas(MediaString));
mp.Close;
Application.ProcessMessages;
mp.free;
end;
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now