1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| // main.cpp
#include <windows.h>
#include <string>
using namespace std;
string GetDataKeyString(HKEY rootKey, wstring regSubKey, wstring regValueKey)
{
/*
LONG WINAPI RegCreateKeyEx(
_In_ HKEY hKey,
_In_ LPCTSTR lpSubKey,
_Reserved_ DWORD Reserved,
_In_opt_ LPTSTR lpClass,
_In_ DWORD dwOptions,
_In_ REGSAM samDesired,
_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
_Out_ PHKEY phkResult,
_Out_opt_ LPDWORD lpdwDisposition
);
LONG RegQueryValueEx(
HKEY hKey,
LPCWSTR lpValueName,
LPDWORD lpReserved,
LPDWORD lpType,
LPBYTE lpData,
LPDWORD lpcbData
);
*/
LONG lResult;
TCHAR regDataKey[MAX_PATH];
DWORD regDataKeyLength = sizeof(regDataKey);
//Creation du handle
HKEY hKey;
if (RegOpenKeyEx(
rootKey,
regSubKey.c_str(),
0,
KEY_ALL_ACCESS,
&hKey) == ERROR_SUCCESS)
{
cout << "Key found" << endl;
//Contrôle
//_tprintf( TEXT("\ RegOpenKeyEx OPENED"));
lResult = RegQueryValueEx(
hKey,
regValueKey.c_str(),
NULL,
NULL,
(LPBYTE)®DataKey,
®DataKeyLength);
if (lResult == ERROR_SUCCESS)
{
cout << "Value found" << endl;
//_tprintf(TEXT("Data : %s\n"), regDataKey);
std::string s( reinterpret_cast<char const*>(regDataKey), regDataKeyLength) ;
return s;
}
else
{
cout << "Value not found" << endl;
}
RegCloseKey( hKey);
}
else
{
cout << "Key not found" << endl;
}
}
int main()
{
string s;
s = GetDataKeyString(HKEY_CURRENT_USER,L"SOFTWARE\\0000\\", L"Essai");
cout << "String Data : " + s << endl;
system("PAUSE");
return 0;
} |
Partager