Click here to Skip to main content
15,914,413 members
Articles / Programming Languages / C++
Article

Checking the serial Number of a CD

Rate me:
Please Sign up or sign in to vote.
2.60/5 (5 votes)
26 Dec 2001 234.8K   2.1K   35   46
This program pops up a message box if the installation CD is not in the CD Drive by checking the serial number of the CD.

Introduction

This program checks the serial number of a CD-ROM and refuses to work if the installation CD is not in the CD Drive. This program assumes that at the Time of installation the serial number of the installation CD is stored at the registry location HKEY_LOCAL_MACHINE\Software\CDsoft\Cds. We can achieve this by adding the below code to our installation program.

GetVolumeInformation(drive,
                     vol,
                     sizeof(vol),
                     &sno,
                     &mf,
                     &sf,
                     NULL,NULL);
RegCreateKeyEx (HKEY_LOCAL_MACHINE, "Software\\CDsoft", 0, 
                NULL,REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY | KEY_ALL_ACCESS, 
                NULL, &childkey, &dispos) ;
RegSetValueEx ( childkey, "Cds", 0, REG_DWORD, ( const BYTE* )(LPDWORD) &sno, size) ;
RegCloseKey ( childkey );

In the OnInitDialog function ,we read the serial number of installation CD from registry by using the code below. And we also start a timer.

HKEY hkeyresult ;
DWORD size=sizeof(DWORD) ;
DWORD type;
BYTE  sno[100];

RegOpenKey ( HKEY_LOCAL_MACHINE, ( LPCTSTR ) "Software\\CDsoft", &hkeyresult );
RegQueryValueEx ( hkeyresult, ( LPCTSTR )"Cds" , 0,&type, sno,&size);
RegCloseKey ( hkeyresult );
serialnoCD=*(DWORD *)sno;

SetTimer(NULL,1000,NULL);

In this program OnTimer calls the function check every second. If the CD is not present in the Drive, this function displays a MessageBox. The function for checking the serial number of a CD-ROM is given below...

void CCDcheckDlg::Check() 
{
    char dbits[100],drive[100];
    int i=0;
    
    DWORD d=GetLogicalDriveStrings(100, dbits);
    strncpy(drive,dbits+i,4);
    
    for (int nDrives = 0; nDrives < 26; nDrives ++)
    {
        if(GetDriveType(drive)==DRIVE_CDROM)
            break;    
        i+=4;
        strncpy(drive,dbits+i,4);
    }

    char vol[40];        
    DWORD mf;            
    DWORD sf,sno;    
    GetVolumeInformation(drive,
                         vol,
                         sizeof(vol),
                         &sno,
                         &mf,
                         &sf,
                         NULL,NULL);

    int ret;
    
    //serialnoCD is the serial number of installation CD..
    if (sno!=serialnoCD){
        ret=MessageBox("To use this software CD Must be in the drive",
                       "Sorry", MB_RETRYCANCEL|MB_ICONERROR|MB_APPLMODAL);    
    }
}

This is only an idea and I don't know much about pirating software. I heard that the serial number is unique for all CD's and it can't be changed but I don't know that is true or false. Anyway I think this method can be useful to reduce or lower piracy. What do you think?

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralChecking the serial Number of a CD Pin
Babita Shivade17-Mar-09 1:49
Babita Shivade17-Mar-09 1:49 
GeneralRe: Checking the serial Number of a CD Pin
mbaocha27-Apr-09 19:10
mbaocha27-Apr-09 19:10 
GeneralFailing to read the serial number Pin
JorgeAxel26-Jan-09 9:46
JorgeAxel26-Jan-09 9:46 
GeneralI CAN STOP THE PIRACY IF I get the solution preventing serail No to be copeid. Pin
prashant Shukla25-Aug-06 7:46
prashant Shukla25-Aug-06 7:46 
GeneralRe: I CAN STOP THE PIRACY IF I get the solution preventing serail No to be copeid. Pin
tamuz23-Jul-07 10:09
tamuz23-Jul-07 10:09 
QuestionHow to Protect the content on CD Pin
Praveen Reddy R7-Dec-05 18:40
Praveen Reddy R7-Dec-05 18:40 
GeneralI can break any Copy Protected CD Pin
Wale Kassim13-Jun-05 9:42
Wale Kassim13-Jun-05 9:42 
GeneralHow to make Copy Protected CD Pin
Praveen Reddy R7-Dec-05 18:08
Praveen Reddy R7-Dec-05 18:08 
GeneralRe: How to make Copy Protected CD Pin
tamuz23-Jul-07 9:56
tamuz23-Jul-07 9:56 
GeneralI can break any Copy Protected CD Pin
Wale Kassim13-Jun-05 9:41
Wale Kassim13-Jun-05 9:41 
GeneralRe: I can break any Copy Protected CD [modified] Pin
prashant Shukla25-Aug-06 7:35
prashant Shukla25-Aug-06 7:35 
GeneralRe: I can break any Copy Protected CD Pin
tamuz23-Jul-07 10:20
tamuz23-Jul-07 10:20 
AnswerRe: I can break any Copy Protected CD [modified] Pin
Wale Kassim2-Sep-07 7:05
Wale Kassim2-Sep-07 7:05 
GeneralDoes not really work Pin
10-Jun-02 22:57
suss10-Jun-02 22:57 
GeneralSorry Doesnt Work Pin
12-Apr-02 15:00
suss12-Apr-02 15:00 
GeneralRe: Sorry Doesnt Work Pin
Anonymous13-Jul-03 2:00
Anonymous13-Jul-03 2:00 
GeneralNaive coders create rich lawyers Pin
22-Feb-02 19:45
suss22-Feb-02 19:45 
I have to agree with the gent on the comment about only slowing down piracy by using a hardware / software scheme. Frivolous techniques like that only keeps the honest users honest.

I first learned ML programming by cracking games for the old school Apple and Commodore 64 (telling my age), then PC games (much easier), then I was cracking commercial applications. Somewhere in there I figured I was better at writing my own. Though not for the shrink-wrap software market. Not with piracy as easy as taking a book to Kinko's, and proprietary code that can be reverse engineered, revision driven sales to get customers paying more than once for something, and costly version upgrades for features and fixes that should have been included with the release, and on and on...

Besides, any pimple-faced kid with a half-cheek knowledge of x86 assembly, Soft-Ice, a matrix algebra book, and a box of twinkies can write a product-key generator for microsoft windoze. Moreover, same kid could easily defeat any copy-protection scheme conceived even dongles protection. I'm not talking about the dongles cracked by bypassing the cheesy routines that call these protection functions. I mean the tough state-machine hardware dongle.

A state machine dongle is essentially a "computer" sitting on the parallel port. THe application makes calls to it and it returns arguments for the application to use as jumppoints to critical routines. To crack, it requires monitoring, either through logic analyzer or breakpoint disassembly, and trapping every iteration of code passing across the parallel port. This requires having a good, active key. I've seen this protection on products where the software was given away, but the key costs 15G.

As an embedded programmer, I suffer not from the trivialities of copy-protection as my code is intertwined within some tangible hardware. It is also open-sourced. I'll give it away for the asking.

I believe in free knowledge. The last time I paid for it, I got a Ph.D .

Anyways, there are only two solutions to this paradigm, although one is trivial:

Make it free. Or make it so expensive no one can buy a copy ... to copy.

Any shrink-wrap software programmer that thinks he has the ultimate protection scheme is no more knowledgeable of his job than the marketing girl down the hall. They both work to create rich lawyers.




Cool | :cool:

LW, PH.D EE
RTP,NC
GeneralRe: Naive coders create rich lawyers Pin
Nish Nishant22-Feb-02 20:27
sitebuilderNish Nishant22-Feb-02 20:27 
GeneralRe: Naive coders create rich lawyers Pin
Hirosh23-Feb-02 7:17
Hirosh23-Feb-02 7:17 
AnswerRe: Naive coders create rich lawyers Pin
tamuz23-Jul-07 10:32
tamuz23-Jul-07 10:32 
GeneralHelpfull but question Pin
27-Jan-02 7:46
suss27-Jan-02 7:46 
QuestionWhat about backup CD copies? Pin
2-Jan-02 3:39
suss2-Jan-02 3:39 
AnswerRe: What about backup CD copies? Pin
2-Jan-02 22:14
suss2-Jan-02 22:14 
GeneralRe: What about backup CD copies? Pin
Anonymous13-Jul-03 2:07
Anonymous13-Jul-03 2:07 
AnswerRe: What about backup CD copies? Pin
HAHAHA_NEXT28-Apr-04 9:58
HAHAHA_NEXT28-Apr-04 9:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.