Запись строковых (REG_SZ) значений в реестр на C++
HKEY OpenKey(HKEY hRootKey, char* strKey) { HKEY hKey; LONG nError = RegOpenKeyEx(hRootKey, strKey, NULL, KEY_ALL_ACCESS, &hKey); if (nError==ERROR_FILE_NOT_FOUND) { cout << "Creating registry key: " << strKey << endl; nError = RegCreateKeyEx(hRootKey, strKey, NULL, NULL, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL, &hKey, NULL); } if (nError) cout << "Error: " << nError << " Could not find or create " << strKey << endl; return hKey; } void SetintVal(HKEY hKey, LPCTSTR lpValue, DWORD data) { LONG nError = RegSetValueEx(hKey, lpValue, NULL, REG_DWORD, (LPBYTE)&data, sizeof(DWORD)); if (nError) cout << "Error: " << nError << " Could not set registry value: " << (char*)lpValue << endl; } DWORD GetintVal(HKEY hKey, LPCTSTR lpValue) { DWORD data; DWORD size = sizeof(data); DWORD type = REG_DWORD; LONG nError = RegQueryValueEx(hKey, lpValue, NULL, &type, (LPBYTE)&data, &size); if (nError==ERROR_FILE_NOT_FOUND) data = 0; SetVal() is called. else if (nError) cout << "Error: " << nError << " Could not get registry value " << (char*)lpValue << endl; return data; } BOOL SetcharVal(HKEY Key,char* subkey,char* StringName,char* Stringdata) { HKEY hKey = OpenKey(Key,subkey); LONG openRes = RegOpenKeyEx(Key, subkey, 0, KEY_ALL_ACCESS , &hKey); if (openRes==ERROR_SUCCESS) { } else { printf("Error opening key."); } LONG setRes = RegSetValueEx (hKey, StringName, 0, REG_SZ, (LPBYTE)Stringdata, strlen(Stringdata)+1); if (setRes == ERROR_SUCCESS) { } else { printf("Error writing to Registry."); } LONG closeOut = RegCloseKey(hKey); if (closeOut == ERROR_SUCCESS) { } else { printf("Error closing key."); } } char* GetCharVal(HKEY Key,char* subkey,char* StringName) { DWORD dwType = REG_SZ; HKEY hKey = 0; char value[1024]; DWORD value_length = 1024; RegOpenKey(HKEY_LOCAL_MACHINE,subkey,&hKey); RegQueryValueEx(hKey, StringName, NULL, &dwType, (LPBYTE)&value, &value_length); RegCloseKey(hKey); return value; }
Я использую этот код.
windows-registry
c++
registry
2021-12-14T12:50:59+00:00
2022-10-05T17:08:16+00:00
Ynnesyncona
Вопросы с похожей тематикой, как у вопроса:
Запись строковых (REG_SZ) значений в реестр на C++
Предупреждение о файлах Cookies
Мы используем файлы cookies для улучшения работы сайта. Оставаясь на нашем сайте, вы соглашаетесь с условиями использования файлов cookies. Чтобы ознакомиться с нашими Положениями о конфиденциальности и об использовании файлов cookie, нажмите здесь.