// ZazouReadRegValue.cpp : définit le point d'entrée pour l'application console. // #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { HKEY rootKey = NULL; HKEY zKey; LPTSTR subKey; LPTSTR value; LPBYTE data; LPBYTE ptr; DWORD dataSize; DWORD keyType; DWORD i; DWORD err; if (argc < 4) { _tprintf(_T("USAGE: %s Clé_Racine Clé_Chemin Nom\n"), argv[0]); return 0; } if (!_tcscmp (argv[1], _T("HKCR"))) rootKey = HKEY_CLASSES_ROOT; if (!_tcscmp (argv[1], _T("HKLM"))) rootKey = HKEY_LOCAL_MACHINE; if (!_tcscmp (argv[1], _T("HKCU"))) rootKey = HKEY_CURRENT_USER; if (!_tcscmp (argv[1], _T("HKU"))) rootKey = HKEY_USERS; if (!rootKey) { if (argc < 4) { _tprintf(_T("USAGE: %s Clé_Racine Clé_Chemin Nom\n"), argv[0]); _tprintf(_T(" Clé = HKCR\n")); _tprintf(_T("ou Clé = HKLM\n")); _tprintf(_T("ou Clé = HKCU\n")); _tprintf(_T("ou Clé = HKU\n")); return 0; } } subKey = argv[2]; value = argv[3]; if (ERROR_SUCCESS != (err = RegOpenKeyEx( rootKey, subKey, 0, KEY_QUERY_VALUE, &zKey ))) { _tprintf(_T("Can't open key: Err=%lu\n"), err); return (int)err; } if (ERROR_SUCCESS == (err = RegQueryValueEx ( zKey, LPCTSTR(value), 0, NULL, NULL, &dataSize ))) { data = (LPBYTE)malloc(dataSize); if (!data) { _tprintf(_T("Can't allocate memory\n")); return 1; } if (ERROR_SUCCESS == (err = RegQueryValueEx ( zKey, LPCTSTR(value), 0, &keyType, data, &dataSize ))) { switch (keyType) { case REG_SZ: _tprintf(_T("\"%s\"\n"), (LPTSTR)data); break; case REG_EXPAND_SZ: ptr = data; _tprintf(_T("\"")); while ((TCHAR)(*ptr)!=_T('\0')) { _tprintf(_T("%c"), (TCHAR)(*ptr)); ptr += sizeof(TCHAR); } _tprintf(_T("\"\n")); break; case REG_MULTI_SZ: ptr = data; while ((TCHAR)(*ptr)!=_T('\0')) { _tprintf(_T("\"%s\"\n"), (LPTSTR)ptr); ptr += _tcslen((LPTSTR)ptr); /* Zéro terminal */ ptr += sizeof(TCHAR); } break; case REG_DWORD: _tprintf(_T("%lu\n"), *(DWORD*)data); break; default: _tprintf(_T("0x")); for (i=0; i