LONG SetKey(LPCWSTR lpSubKey, LPCWSTR lpData, DWORD dwSize) const { if (!IsValidHandle()) return ERROR_INVALID_HANDLE; return RegSetValueW(hKey(), lpSubKey, REG_SZ, lpData, dwSize); }
LONG DeleteValue(LPCWSTR lpValueName) const { if (!IsValidHandle()) return ERROR_INVALID_HANDLE; return RegDeleteValueW(hKey(), lpValueName); }
int CXTPRegistryManager::EnumValues(LPCTSTR lpszSection, CMap<CString, LPCTSTR, DWORD, DWORD&>* mapItems, CStringArray * arrayNames) { ASSERT(lpszSection != NULL); CHKey hKey(GetSectionKey(lpszSection, KEY_READ)); if (hKey == NULL) return 0; int index = 0; TCHAR szValue[512]; DWORD dwLen = 512; DWORD dwType; while (::RegEnumValue(hKey, index++, szValue, &dwLen, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS) { if (mapItems) mapItems->SetAt(szValue, dwType); if (arrayNames) arrayNames->Add(szValue); dwLen = 512; } return --index; }
LONG QueryKey(LPCWSTR lpSubKey, LPWSTR lpData, PLONG lpSize) const { if (!IsValidHandle()) return ERROR_INVALID_HANDLE; return RegQueryValueW(hKey(), lpSubKey, lpData, lpSize); }
LONG SetValue(LPCWSTR lpValueName = NULL, const LPVOID lpData = NULL, DWORD dwSize = 0, DWORD dwType = REG_BINARY) const { if (!IsValidHandle()) return ERROR_INVALID_HANDLE; return RegSetValueExW(hKey(), lpValueName, NULL, dwType, (CONST LPBYTE)lpData, dwSize); }
LONG QueryValue(LPCWSTR lpValueName = NULL, LPVOID lpData = NULL, LPDWORD lpSize = 0, LPDWORD lpType = NULL) const { if (!IsValidHandle()) return ERROR_INVALID_HANDLE; return RegQueryValueExW(hKey(), lpValueName, NULL, lpType, (LPBYTE)lpData, lpSize); }
bool Autorun::is() { DWORD size = 0; utils::Scope(HKEY, &::RegCloseKey) hKey(NULL); ::RegOpenKeyEx( HKEY_CURRENT_USER, RUN_REG_KEY, 0, KEY_QUERY_VALUE, &hKey.get()); ::RegQueryValueEx(hKey.get(), g_name, 0, NULL, NULL, &size); std::vector<BYTE> buffer(size); return ::RegQueryValueEx(hKey.get(), g_name, 0, NULL, buffer.data(), &size) == ERROR_SUCCESS; }
void Autorun::on() { utils::Scope(HKEY, &::RegCloseKey) hKey(NULL); ::RegOpenKeyEx(HKEY_CURRENT_USER, RUN_REG_KEY, 0, KEY_SET_VALUE, &hKey.get()); ::RegSetValueEx(hKey.get(), g_name, 0, REG_SZ, (BYTE *)g_path.c_str(), (DWORD)g_path.size() + 1); }
/// Closes the embedded handle if it is valid. bool Close() { if (!IsValidHandle()) return false; LONG lRegError = RegCloseKey(hKey()); if (lRegError == ERROR_SUCCESS) { hObject = INVALID_HANDLE_VALUE; return true; } else { SetLastError(lRegError); return false; } }
int CXTPRegistryManager::EnumKeys(LPCTSTR lpszSection, CStringArray & arrayKeys) { ASSERT(lpszSection != NULL); CHKey hKey(GetSectionKey(lpszSection, KEY_READ)); if (hKey == NULL) return 0; int index = 0; TCHAR szValue[512]; DWORD dwLen = 512; while (::RegEnumKeyEx(hKey, index++, szValue, &dwLen, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { arrayKeys.Add(szValue); dwLen = 512; } return --index; }
void Autorun::off() { utils::Scope(HKEY, &::RegCloseKey) hKey(NULL); ::RegOpenKeyEx(HKEY_CURRENT_USER, RUN_REG_KEY, 0, KEY_SET_VALUE, &hKey.get()); ::RegDeleteValue(hKey.get(), g_name); }