Click here to Skip to main content
15,885,998 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.1K   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 
Dear Mr. Engr. ‘Wale, from Nigeria, West Africa

You are right about some people in Africa, you are right about some people waste money building nuclear missiles. But what about "I can break any Copy Protected CD"? Are you sure. Try that http://payoff.co.nr

No encryption, no data onto CD/DVD, no check for original media. Look tests on a page. If It'll stop you, tell me how can you copy it

Let's work together

Regards,
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 
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.