→OS関連
→[[OS関連]]

-[[参照先:http://www.codeproject.com/useritems/zolaman.asp]]
 BSTR GetProductKey()
 {
  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++)
    {
     ProductKeyExtract[ByteCounter - 52] = DigitalProductID[ByteCounter];
    }
 
    //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&#44228;&#49328;
    ProductKeyExtract[ByteConvert] = 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);
 
  //Relese Memory
  if(DigitalProductID) free(DigitalProductID);
 
  return strResult.AllocSysString();
 }

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS