Click here to Skip to main content
6,595,854 members and growing! (17,716 online)
Email Password   helpLost your password?
General Reading » Hardware & System » General     Intermediate

Extract Window Product Key - With an API !

By handsomeme

Get a window's product key!
VC6, VC7, VC7.1, VC8.0Win2K, WinXP, Win2003, Visual Studio, Dev
Posted:21 Aug 2006
Views:36,203
Bookmarked:15 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 2.78 Rating: 3.07 out of 5
3 votes, 37.5%
1

2
1 vote, 12.5%
3
1 vote, 12.5%
4
3 votes, 37.5%
5

Introduction

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[] = {
       "B","C","D","F","G","H","J","K","M",
       "P","Q","R","T","V","W","X","Y",
       "2","3","4","6","7","8","9",NULL
      }; 

 // HKLM\\SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion 열기  

 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, NT_CURRENT, 
    REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 
    &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++)
   {
    ProductKeyExtract52> = 
             DigitalProductID;
   }

   //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;  //XOR&#44228;&#49328; 

   ProductKeyExtract = nCur / 24;
   nCur = nCur % 24;
  }   
  
  strrev(sCDKey);
  strcat(sCDKey, KeyChars[nCur]);
  strrev(sCDKey);

  //Insert "-" 


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

 //Insert Product Key into Return value 


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

 //Close Registry

 RegCloseKey(hRegistryKey); 

 //Release Memory

 if(DigitalProductID) free(DigitalProductID); 

 return strResult.AllocSysString();
}

If you have any questions, mail them to me!

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

About the Author

handsomeme


Member
Yeah, I'm programmer of the mediasolution in SEOUL, Korea. KKK

Bye
Occupation: Web Developer
Location: United States United States

Other popular Hardware & System articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
GeneralWork version is here [modified] Pinmemberdima_kdl8:03 30 Jan '09  
GeneralRe: Work version is here Pinmembertttony0718:36 25 Aug '09  
GeneralC# & VB.NET Code Pinmembercrouchie19986:46 4 Apr '07  
GeneralNice code PinmemberDouglas R. Keesler21:15 6 Jan '07  
GeneralSmall bug Pinmembermcanti4:42 6 Jan '07  
GeneralRe: Small bug Pinmembersstraw13:21 17 Oct '07  
GeneralWindows Vista PinmemberGabriel Topala18:14 16 Sep '06  
GeneralRe: Windows Vista Pinmemberhandsomeme17:59 17 Sep '06  
GeneralRe: Windows Vista Pinmembertzukuei1:49 18 Oct '06  
GeneralRe: Windows Vista PinmemberGabriel Topala2:35 18 Oct '06  
GeneralRe: Windows Vista Pinmembertzukuei18:10 18 Oct '06  
GeneralRe: Windows Vista PinmemberGabriel Topala19:00 18 Oct '06  
GeneralRe: Windows Vista [modified] Pinmembertzukuei17:33 19 Oct '06  
GeneralRe: Windows Vista Pinmemberawjapp8:34 21 Apr '07  
GeneralSolo Pinmemberhvw20:13 22 Aug '06  
GeneralWow Good C# I like C# and used this! Pinmemberhandsomeme15:38 22 Aug '06  
Generalin c# Pinmembersolo7:17 22 Aug '06  
GeneralRe: in c#, not work! PinmemberBug Me Not2:56 7 Nov '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Aug 2006
Editor:
Copyright 2006 by handsomeme
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project