Показать сообщение отдельно

  #2  
Старый 11.12.2006, 23:40
Deem3n®
Постоянный
Регистрация: 19.09.2005
Сообщений: 408
Провел на форуме:
3730496

Репутация: 519
По умолчанию

Ну если речь зашла о советах и уловках (тобишь твики), выкладываю свою коллекцию твиков - REG файл с подробными комментариями:
http://rapidshare.com/files/7069310/tweaks.reg.html

Для кодеров:
вот еще ф-ция getWindowsSN которую писал недавно, для получения серийного номера винды (MS Office тоже - только надо изменить путь для digitalProductId) из реестра:
Код:
//
//  FUNCTION: getWindowsSN()
//
//  PURPOSE: To obtain Windows product key (serial number)
//
//  COMMENTS:
//
//    This function, reads from registry a digitalProductId,
//    after that this a part of this digitalProductId 
//    is converted to a product key (serial number)
//
//    Function return:
//    1 - on success
//    0 - on error
//
int getWindowsSN(LPTSTR sn)
{
	// this is a digitalProductId what will be read from registry
	LPBYTE digitalProductId;

	HKEY hKey;		// handle to registry key
	DWORD dwType;	// type of data stored in the registry value
	DWORD dwSize;	// size of the buffer pointed to RegQueryValueEx

	// open registry key
	LONG ret = RegOpenKeyEx(
								HKEY_LOCAL_MACHINE, 
								"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 
								0,
								KEY_READ,
								&hKey
							);
	
	// if the RegOpenKeyEx function succeeds
	if (ret == ERROR_SUCCESS)
	{
		dwSize = 0;
		// query registry key first time - to get DigitalProductId size
		ret = RegQueryValueEx(hKey,	"DigitalProductId", NULL, &dwType, NULL, &dwSize);

		// if error occurs
		if (ret != ERROR_SUCCESS)
			return 0;

        // alloc memory for digitalProductId array
		digitalProductId = new BYTE[dwSize];

		// and query registry key second time - to get DigitalProductId
		ret = RegQueryValueEx(hKey,	"DigitalProductId", NULL, &dwType, (LPBYTE)digitalProductId, &dwSize);

		// if error occurs
		if (ret != ERROR_SUCCESS)
			return 0;

		// Offset of first byte of encoded product key in 
		// 'DigitalProductId" REG_BINARY value. Offset = 34H.
		int keyStartIndex = 52;
		
		// Offset of last byte of encoded product key in 
		//  'DigitalProductId" REG_BINARY value. Offset = 43H.
		int keyEndIndex = keyStartIndex + 15;
    
		// Possible alpha-numeric characters in product key.
		char digits[] = {	
							'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 
							'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9'
						};

		// Length of decoded product key
		int decodeLength = 29 + 1;
		
		// Length of decoded product key in byte-form
		int decodeStringLength = 15;

		// product key in byte-form
		BYTE BinaryKey[15];
		// additional index variable
		int j = 0;
		
		// To obtain s/n we need 15 bytes from 52 in BinaryKey
		// copy them in BinaryKey array
		for (int i = keyStartIndex; i <= keyEndIndex; i++)
			BinaryKey[j++] = digitalProductId[i];

		// decoding the current symbol
		// Note: the symbols are decoded from last to first!
		for (int i = decodeLength - 1; i >= 0; i--)
		{
			// Every sixth char is a separator.
			if ((i + 1) % 6 == 0)
				sn[i] = '-';
			else
			{
				// Do the actual decoding.
				int digitMapIndex = 0;
				for (int j = decodeStringLength - 1; j >= 0; j--)
				{
					int byteValue = (digitMapIndex << 8) | BinaryKey[j];
					BinaryKey[j] = (byteValue / 24);
					digitMapIndex = byteValue % 24;
					sn[i] = digits[digitMapIndex];
				}
			}
		}
		// last char is '\0'
		sn[decodeLength - 1] = 0;
	
		// free memory for digitalProductId array
		delete (digitalProductId);
	}
	// if product key was obtained - return success
	return 1;
}
Юзать ее очень просто:
Код:
TCHAR buff[30];

if (getWindowsSN(buff))
	MessageBox(buff, "Windows S/N", MB_ICONINFORMATION);
else
	MessageBox("Error obtaining Windows S/N!", "Error", MB_ICONERROR);
 
Ответить с цитированием