enum PreKeys { HKLM, HKCU, HKCC, HKDD, HKCR, HKU, HKPD, }; // Fungsi Untuk membaca value registry yang berupa string char* ReadStringValue(PreKeys PreKey, char *Subkey, char *Value) { HKEY hPkey, hKey; LONG lResult; BYTE buffer[1024] = {'\0'}; // Inisiasi agar tidak berisi sampah hPkey = GetPredefinedKey(PreKey); char *pszData; char *Data = new char[1024]; // Buffer (heap) untuk return unsigned long size = sizeof(buffer)-1; lResult = RegOpenKeyEx(hPkey, Subkey, 0, KEY_READ, &hKey); if (lResult == ERROR_SUCCESS) { lResult = RegQueryValueEx(hKey, Value, 0, 0, buffer, &size); if (lResult == ERROR_SUCCESS) { pszData = (char*) buffer; strncpy(Data, pszData, sizeof(Data)-1); delete pszData; return Data; } else { return NULL; } } else { return NULL; } RegCloseKey(hKey); }
Terus nanti penggunaanya gini :
char* value = ReadStringValue(HKCU, "SOFTWARE\\My App\\setting", "setting1"); if (strstr("yes", value) > 0 ){ // do something }
0 komentar:
Posting Komentar