ТОР 5 статей: Методические подходы к анализу финансового состояния предприятия Проблема периодизации русской литературы ХХ века. Краткая характеристика второй половины ХХ века Характеристика шлифовальных кругов и ее маркировка Служебные части речи. Предлог. Союз. Частицы КАТЕГОРИИ:
|
Чтение содержимого раздела реестра#include <windows.h> #include <iostream.h> #include <iomanip.h> #include <string.h> #define STR_HKEY_LOCAL_MACHINE "HKEY_LOCAL_MACHINE" #define STR_HKEY_CLASSES_ROOT "HKEY_CLASSES_ROOT" #define STR_HKEY_USERS "HKEY_USERS" #define STR_HKEY_CURRENT_USER "HKEY_CURRENT_USER" #define LEN_HKEY_LOCAL_MACHINE (sizeof(STR_HKEY_LOCAL_MACHINE)-1) #define LEN_HKEY_CLASSES_ROOT (sizeof(STR_HKEY_CLASSES_ROOT)-1) #define LEN_HKEY_USERS (sizeof(STR_HKEY_USERS)-1) #define LEN_HKEY_CURRENT_USER (sizeof(STR_HKEY_CURRENT_USER)-1) #define SWAP_ENDIAN(x) (((x<<24)&0xFF000000)|((x<<8)&0xFF0000)|\ ((x>>8)&0xFF00)|((x>>24)|0xFF))
void printval(unsigned char *pBuffer, DWORD dwType, DWORD dwSize) { switch (dwType) { case REG_BINARY: cout << "Binary data:"; {
for (unsigned int i = 0; i < dwSize; i++) { if (i % 16 == 0) cout << '\n'; cout.fill('0'); cout << hex << setw(2) << (unsigned int)(pBuffer[i]) << ' '; } } cout << '\n'; break; case REG_DWORD: cout.fill('0'); cout << "Double word: " << hex << setw(8) << *((unsigned int *)pBuffer) << '\n'; break; case REG_DWORD_BIG_ENDIAN: // Intel specific! cout.fill('0'); cout << "Big-endian double word: " << hex << setw(8) << SWAP_ENDIAN(*((unsigned int *)pBuffer)) << '\n'; break; case REG_EXPAND_SZ: cout << "Expandable string: " << pBuffer << '\n'; break; case REG_LINK: cout << "Unicode link."; break; case REG_MULTI_SZ: cout << "Multiple strings:\n"; { char *pStr; int i; for (i = 0, pStr = (char *)pBuffer; *pStr!= '\0'; i++, pStr += strlen((char *)pStr) + 1) { cout << "String " << i << ": " << pStr << '\n'; } } break; case REG_NONE: cout << "Undefined value type.\n"; break; case REG_RESOURCE_LIST: cout << "Resource list.\n"; break; case REG_SZ: cout << "String: " << pBuffer << '\n'; break; default: cout << "Invalid type code.\n"; break; } } void main(void) { char szKey[1000]; char *pKey; HKEY hKey, hSubKey; DWORD dwType; DWORD dwSize; unsigned char *pBuffer; int nKey; while (1) { cout << "Enter key: "; cin.getline(szKey, 1000); nKey = strcspn(szKey, "\\"); hKey = NULL; if (!strncmp(szKey, STR_HKEY_LOCAL_MACHINE, nKey) && nKey == LEN_HKEY_LOCAL_MACHINE) hKey = HKEY_LOCAL_MACHINE; if (!strncmp(szKey, STR_HKEY_CLASSES_ROOT, nKey) && nKey == LEN_HKEY_CLASSES_ROOT) hKey = HKEY_CLASSES_ROOT; if (!strncmp(szKey, STR_HKEY_USERS, nKey) && nKey == LEN_HKEY_USERS) hKey = HKEY_USERS; if (!strncmp(szKey, STR_HKEY_CURRENT_USER, nKey) && nKey == LEN_HKEY_CURRENT_USER) hKey = HKEY_CURRENT_USER; if (hKey == NULL || szKey[nKey]!= '\\') { cout << "Invalid key.\n"; continue; } pKey = szKey + nKey + 1; nKey = strcspn(pKey, "\\"); while (pKey[nKey] == '\\') { pKey[nKey] = '\0'; if (RegOpenKeyEx(hKey, pKey, NULL, KEY_READ,&hSubKey) == ERROR_SUCCESS) { RegCloseKey(hKey); hKey = hSubKey; } else { RegCloseKey(hKey); hKey = NULL; break; } pKey += nKey + 1; nKey = strcspn(pKey, "\\"); } if (hKey == NULL) { cout << "Invalid key.\n"; continue; } if (RegQueryValueEx(hKey, pKey, NULL, &dwType, NULL,&dwSize) == ERROR_SUCCESS) { pBuffer = (unsigned char *)malloc(dwSize); if (pBuffer == NULL) { cout << "Insufficient memory.\n"; break; } if (RegQueryValueEx(hKey, pKey, NULL, &dwType, pBuffer,&dwSize) == ERROR_SUCCESS) printval(pBuffer, dwType, dwSize); else cout << "Error reading key.\n"; free(pBuffer); } else cout << "Error reading key.\n"; RegCloseKey(hKey); } }
Не нашли, что искали? Воспользуйтесь поиском:
|