Click here to Skip to main content
13,293,178 members (43,156 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 21 Aug 2006

Extract Window Product Key - With an API !

, 21 Aug 2006
Rate this:
Please Sign up or sign in to vote.
Get a window's product key!


Hi. This article shows a very usuful function!! This function gets a window's product key using the Windows API that can used with any window and can be used with any tool and language, VB, C++, VS6, VS 7, 8, and so on.

The code

BSTR GetProductKey()
 Window Product Key Extract

 CString strResult;        //Return a Window Product Key
 HKEY hRegistryKey;        //Registry Handler 
 BYTE   *DigitalProductID; //Digital Product Key Value 
 DWORD DataLength;         //Digital Product Key Length 

 BYTE ProductKeyExtract [15]; //Extract Key 

char sCDKey  [256];   //Temp, adding a Window Product Key
 long ByteCounter;    //Counter
 long ByteConvert;    //Convert

 int  nCur;      //XOR calculate 

 char *KeyChars[] = {

 // HKLM\\SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion 열기  
    &hRegistryKey) == ERROR_SUCCESS)
  DataLength = 164; 

  //Allocate Memory
  DigitalProductID = (BYTE *)malloc(DataLength);    

  //Memory Initializationd
  memset(DigitalProductID, 0, DataLength); 

 //Digital Product Key Open

  if(RegQueryValueEx(hRegistryKey, "DigitalProductId", 
   NULL, NULL, DigitalProductID, &DataLength) == ERROR_SUCCESS)
   //reading a value start position 52, by 66
   for(ByteCounter=52; ByteCounter<=66; ByteCounter++)
    ProductKeyExtract[ByteCounter - 52] = 

   //Last Indexer
   ProductKeyExtract[sizeof(ProductKeyExtract)] = NULL;

 //Start Converting job, Next Step 

 memset(sCDKey, 0, sizeof(sCDKey)); 

 for(ByteCounter=24; ByteCounter>=0; ByteCounter--)
  nCur = 0; 

  for(ByteConvert=14; ByteConvert>=0; ByteConvert--)

   nCur = (nCur * 256) ^ ProductKeyExtract[ByteConvert];  //XOR계산 
   ProductKeyExtract[ByteConvert] = nCur / 24;
   nCur = nCur % 24;
  strcat(sCDKey, KeyChars[nCur]);

  //Insert "-" 

  if(!(ByteCounter % 5) && (ByteCounter))
   strcat(sCDKey, "-"); 

 //Insert Product Key into Return value 

 strResult.Format("%s", sCDKey); 

 //Close Registry

 //Release Memory
 if(DigitalProductID) free(DigitalProductID); 

 return strResult.AllocSysString();

If you have any questions, mail them to me!


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


About the Author

United States United States
Yeah, I'm programmer in SEOUL, Korea.

You may also be interested in...

Comments and Discussions

QuestionCouple serious bugs in this Pin
pickaname26-Nov-13 12:20
memberpickaname26-Nov-13 12:20 
AnswerRe: Couple serious bugs in this Pin
handsomeme8-Apr-14 3:01
memberhandsomeme8-Apr-14 3:01 
GeneralWork version is here [modified] Pin
dima_kdl30-Jan-09 8:03
memberdima_kdl30-Jan-09 8:03 
GeneralRe: Work version is here Pin
tttony0725-Aug-09 18:36
membertttony0725-Aug-09 18:36 
AnswerRe: Work version is here Pin
danielsage6-Feb-11 12:07
memberdanielsage6-Feb-11 12:07 
GeneralRe: Work version is here Pin
tttony076-Feb-11 15:46
membertttony076-Feb-11 15:46 
GeneralC# & VB.NET Code Pin
crouchie19984-Apr-07 6:46
membercrouchie19984-Apr-07 6:46 
GeneralNice code Pin
Douglas R. Keesler6-Jan-07 21:15
memberDouglas R. Keesler6-Jan-07 21:15 
GeneralSmall bug Pin
mcanti6-Jan-07 4:42
membermcanti6-Jan-07 4:42 
GeneralRe: Small bug Pin
sstraw17-Oct-07 13:21
membersstraw17-Oct-07 13:21 
GeneralWindows Vista Pin
Gabriel Topala16-Sep-06 18:14
memberGabriel Topala16-Sep-06 18:14 
GeneralRe: Windows Vista Pin
handsomeme17-Sep-06 17:59
memberhandsomeme17-Sep-06 17:59 
GeneralRe: Windows Vista Pin
tzukuei18-Oct-06 1:49
membertzukuei18-Oct-06 1:49 
GeneralRe: Windows Vista Pin
Gabriel Topala18-Oct-06 2:35
memberGabriel Topala18-Oct-06 2:35 
GeneralRe: Windows Vista Pin
tzukuei18-Oct-06 18:10
membertzukuei18-Oct-06 18:10 
GeneralRe: Windows Vista Pin
Gabriel Topala18-Oct-06 19:00
memberGabriel Topala18-Oct-06 19:00 
GeneralRe: Windows Vista [modified] Pin
tzukuei19-Oct-06 17:33
membertzukuei19-Oct-06 17:33 
GeneralRe: Windows Vista Pin
awjapp21-Apr-07 8:34
memberawjapp21-Apr-07 8:34 
GeneralSolo Pin
hvw22-Aug-06 20:13
memberhvw22-Aug-06 20:13 
GeneralWow Good C# I like C# and used this! Pin
handsomeme22-Aug-06 15:38
memberhandsomeme22-Aug-06 15:38 
Generalin c# Pin
solo22-Aug-06 7:17
membersolo22-Aug-06 7:17 
GeneralRe: in c#, not work! Pin
Bug Me Not7-Nov-09 2:56
memberBug Me Not7-Nov-09 2:56 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 21 Aug 2006
Article Copyright 2006 by handsomeme
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid