Checking the serial Number of a CD






2.60/5 (5 votes)
Dec 27, 2001

236941

2096
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?