diff --git a/.github/workflows/ClangFormat.yml b/.github/workflows/ClangFormat.yml index 9bcecdc..fed69a1 100644 --- a/.github/workflows/ClangFormat.yml +++ b/.github/workflows/ClangFormat.yml @@ -37,4 +37,5 @@ jobs: git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" git diff --exit-code || (git add -A && git commit -m "Auto-fix formatting issues") - git push \ No newline at end of file + git push + diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 0511c11..fac8035 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -29,6 +29,7 @@ jobs: with: name: lib-artifact path: | + RegistryHelper/RegistryHelper.h x64/Release/RegistryHelper.lib x64/Release/RegistryHelper.pdb x64/Release/RegistryHelper.h diff --git a/Example/main.cpp b/Example/main.cpp index 30022d7..1368518 100644 --- a/Example/main.cpp +++ b/Example/main.cpp @@ -1,74 +1,70 @@ #include "RegistryHelper.h" #include -int main() -{ - try - { - RegistryHelper registryHelper; - std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; - HKEY hKey = HKEY_LOCAL_MACHINE; +int main() { + try { + RegistryHelper registryHelper; + std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; + HKEY hKey = HKEY_LOCAL_MACHINE; - // - // Example 1: Reading DWORD value (REG_DWORD) - // - std::wstring valueNameDword = L"BootDriverFlags"; + // + // Example 1: Reading DWORD value (REG_DWORD) + // + std::wstring valueNameDword = L"BootDriverFlags"; - DWORD dwordValue = registryHelper.RegGetDword(hKey, subKey, valueNameDword); - std::wcout << L"DWORD Value: " << dwordValue << std::endl; + DWORD dwordValue = registryHelper.RegGetDword(hKey, subKey, valueNameDword); + std::wcout << L"DWORD Value: " << dwordValue << std::endl; - // - // Example 2: Reading String value (REG_SZ) - // - std::wstring valueNameString = L"CurrentUser"; + // + // Example 2: Reading String value (REG_SZ) + // + std::wstring valueNameString = L"CurrentUser"; - std::wstring stringValue = registryHelper.RegGetString(hKey, subKey, valueNameString); - std::wcout << L"String Value: " << stringValue << std::endl; + std::wstring stringValue = + registryHelper.RegGetString(hKey, subKey, valueNameString); + std::wcout << L"String Value: " << stringValue << std::endl; - // - // Example 3: Reading Multi-String value (REG_MULTI_SZ) - // - std::wstring valueNameMultiString = L"PreshutdownOrder"; + // + // Example 3: Reading Multi-String value (REG_MULTI_SZ) + // + std::wstring valueNameMultiString = L"PreshutdownOrder"; - std::vector multiStringValue = - registryHelper.RegGetMultiString(hKey, subKey, valueNameMultiString); + std::vector multiStringValue = + registryHelper.RegGetMultiString(hKey, subKey, valueNameMultiString); - std::wcout << L"Multi-String Values: " << std::endl; - for (const auto& str : multiStringValue) - { - std::wcout << L" " << str << std::endl; - } + std::wcout << L"Multi-String Values: " << std::endl; + for (const auto &str : multiStringValue) { + std::wcout << L" " << str << std::endl; + } - // - // Example 4: Enumerate sub-keys - // - std::vector> subKeys = registryHelper.RegEnumSubKeys(hKey, subKey); + // + // Example 4: Enumerate sub-keys + // + std::vector> subKeys = + registryHelper.RegEnumSubKeys(hKey, subKey); - std::wcout << L"Sub-Keys: " << std::endl; - for (const auto& subKeyPair : subKeys) - { - std::wcout << L" " << subKeyPair.first << std::endl; - } + std::wcout << L"Sub-Keys: " << std::endl; + for (const auto &subKeyPair : subKeys) { + std::wcout << L" " << subKeyPair.first << std::endl; + } - // - // Example 5: Enumerate values - // - std::vector> values = registryHelper.RegEnumValues(hKey, subKey); + // + // Example 5: Enumerate values + // + std::vector> values = + registryHelper.RegEnumValues(hKey, subKey); - std::wcout << L"Values: " << std::endl; - for (const auto& valuePair : values) - { - std::wcout << L" " << valuePair.first << L" (Type: " << valuePair.second << L")" << std::endl; - } - } - catch (const RegistryError& ex) - { - std::cerr << "Registry Error: " << ex.what() << " (Error Code: " << ex.ErrorCode() << ")" << std::endl; - } - catch (const std::exception& ex) - { - std::cerr << "Error: " << ex.what() << std::endl; - } + std::wcout << L"Values: " << std::endl; + for (const auto &valuePair : values) { + std::wcout << L" " << valuePair.first << L" (Type: " << valuePair.second + << L")" << std::endl; + } + } catch (const RegistryError &ex) { + std::cerr << "Registry Error: " << ex.what() + << " (Error Code: " << ex.ErrorCode() << ")" << std::endl; + } catch (const std::exception &ex) { + std::cerr << "Error: " << ex.what() << std::endl; + } - return 0; + return 0; } diff --git a/README.md b/README.md index e476aba..81589b4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,13 @@ std::vector> subKeys = // Example 5: Enumerate values std::vector> values = registryHelper.RegEnumValues(hKey, subKey); + + +// Set DWORD value under a non-existing key (will create the key first) +registryHelper.RegSetDword(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\NewApp", + L"NewDWORD", + 123); ``` Adjust the registry keys, subkeys, and value names based on your specific use case. diff --git a/RegistryHelper/RegistryHelper.cpp b/RegistryHelper/RegistryHelper.cpp index f1aa810..841ac47 100644 --- a/RegistryHelper/RegistryHelper.cpp +++ b/RegistryHelper/RegistryHelper.cpp @@ -3,27 +3,17 @@ #include // Constructor initializes the error code to ERROR_SUCCESS -RegistryHelper::RegistryHelper() - : m_errorCode(ERROR_SUCCESS) -{ -} +RegistryHelper::RegistryHelper() : m_errorCode(ERROR_SUCCESS) {} // Read a DWORD value from the registry DWORD -RegistryHelper::RegGetDword(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value) -{ +RegistryHelper::RegGetDword(HKEY hKey, const std::wstring &subKey, + const std::wstring &value) { DWORD data{}; DWORD dataSize = sizeof(data); - m_errorCode = ::RegGetValue(hKey, - subKey.c_str(), - value.c_str(), - RRF_RT_REG_DWORD, - nullptr, - &data, - &dataSize); + m_errorCode = ::RegGetValue(hKey, subKey.c_str(), value.c_str(), + RRF_RT_REG_DWORD, nullptr, &data, &dataSize); if (m_errorCode != ERROR_SUCCESS) { // Throw a RegistryError exception if an error occurs @@ -34,20 +24,12 @@ RegistryHelper::RegGetDword(HKEY hKey, } // Read a string value from the registry -std::wstring -RegistryHelper::RegGetString(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value) -{ +std::wstring RegistryHelper::RegGetString(HKEY hKey, const std::wstring &subKey, + const std::wstring &value) { // Retrieve the size of the string value data DWORD dataSize{}; - m_errorCode = ::RegGetValue(hKey, - subKey.c_str(), - value.c_str(), - RRF_RT_REG_SZ, - nullptr, - nullptr, - &dataSize); + m_errorCode = ::RegGetValue(hKey, subKey.c_str(), value.c_str(), + RRF_RT_REG_SZ, nullptr, nullptr, &dataSize); // Check if the value information retrieval was successful if (m_errorCode != ERROR_SUCCESS) { @@ -58,13 +40,8 @@ RegistryHelper::RegGetString(HKEY hKey, std::vector data(dataSize / sizeof(wchar_t)); // Retrieve the actual string value data - m_errorCode = ::RegGetValue(hKey, - subKey.c_str(), - value.c_str(), - RRF_RT_REG_SZ, - nullptr, - data.data(), - &dataSize); + m_errorCode = ::RegGetValue(hKey, subKey.c_str(), value.c_str(), + RRF_RT_REG_SZ, nullptr, data.data(), &dataSize); // Check if the value data retrieval was successful if (m_errorCode != ERROR_SUCCESS) { @@ -80,19 +57,12 @@ RegistryHelper::RegGetString(HKEY hKey, // Read a multi-string value from the registry std::vector -RegistryHelper::RegGetMultiString(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value) -{ +RegistryHelper::RegGetMultiString(HKEY hKey, const std::wstring &subKey, + const std::wstring &value) { // Retrieve the size of the multi-string value data DWORD dataSize{}; - m_errorCode = ::RegGetValue(hKey, - subKey.c_str(), - value.c_str(), - RRF_RT_REG_MULTI_SZ, - nullptr, - nullptr, - &dataSize); + m_errorCode = ::RegGetValue(hKey, subKey.c_str(), value.c_str(), + RRF_RT_REG_MULTI_SZ, nullptr, nullptr, &dataSize); // Check if the value information retrieval was successful if (m_errorCode != ERROR_SUCCESS) { @@ -103,13 +73,9 @@ RegistryHelper::RegGetMultiString(HKEY hKey, std::vector data(dataSize / sizeof(wchar_t)); // Retrieve the actual multi-string value data - m_errorCode = ::RegGetValue(hKey, - subKey.c_str(), - value.c_str(), - RRF_RT_REG_MULTI_SZ, - nullptr, - data.data(), - &dataSize); + m_errorCode = + ::RegGetValue(hKey, subKey.c_str(), value.c_str(), RRF_RT_REG_MULTI_SZ, + nullptr, data.data(), &dataSize); // Check if the value data retrieval was successful if (m_errorCode != ERROR_SUCCESS) { @@ -121,10 +87,10 @@ RegistryHelper::RegGetMultiString(HKEY hKey, // Parse the double-NUL-terminated string into a vector of wstrings std::vector result; - const wchar_t* currStringPtr = data.data(); + const wchar_t *currStringPtr = data.data(); while (*currStringPtr != L'\0') { const size_t currStringLength = wcslen(currStringPtr); - result.push_back(std::wstring{ currStringPtr, currStringLength }); + result.push_back(std::wstring{currStringPtr, currStringLength}); currStringPtr += currStringLength + 1; } @@ -133,8 +99,7 @@ RegistryHelper::RegGetMultiString(HKEY hKey, } std::vector> -RegistryHelper::RegEnumSubKeys(HKEY hKey, const std::wstring& subKey) -{ +RegistryHelper::RegEnumSubKeys(HKEY hKey, const std::wstring &subKey) { HKEY keyHandle; // Open the specified key (root key or subkey) @@ -151,8 +116,7 @@ RegistryHelper::RegEnumSubKeys(HKEY hKey, const std::wstring& subKey) nullptr, // No user-defined class nullptr, // No user-defined class size nullptr, // Reserved - &subKeyCount, - &maxSubKeyNameLen, + &subKeyCount, &maxSubKeyNameLen, nullptr, // No subkey class length nullptr, // No value count nullptr, // No value max length @@ -165,56 +129,52 @@ RegistryHelper::RegEnumSubKeys(HKEY hKey, const std::wstring& subKey) // Handle error, close the key handle and return RegCloseKey(keyHandle); throw RegistryError{ - "RegQueryInfoKey failed while preparing for value enumeration", retCode - }; - } - - // Allocate a buffer for storing subkey names - maxSubKeyNameLen++; + "RegQueryInfoKey failed while preparing for value enumeration", + retCode}; + }; +} - auto nameBuffer = std::make_unique(maxSubKeyNameLen); +// Allocate a buffer for storing subkey names +maxSubKeyNameLen++; - // Vector to store pairs of subkey names and types - std::vector> subKeys; +auto nameBuffer = std::make_unique(maxSubKeyNameLen); - // Enumerate subkeys under the registry key - for (DWORD index = 0; index < subKeyCount; index++) { - DWORD subKeyNameLen = maxSubKeyNameLen; +// Vector to store pairs of subkey names and types +std::vector> subKeys; - // Retrieve information about the specified subkey - retCode = ::RegEnumKeyEx(keyHandle, - index, - nameBuffer.get(), - &subKeyNameLen, - nullptr, // Reserved - nullptr, // No class information - nullptr, // No class size - nullptr // No last write time - ); +// Enumerate subkeys under the registry key +for (DWORD index = 0; index < subKeyCount; index++) { + DWORD subKeyNameLen = maxSubKeyNameLen; - // Check if the subkey information retrieval was successful - if (retCode != ERROR_SUCCESS) { - // Close the key handle and handle the error - RegCloseKey(keyHandle); - throw RegistryError{ "Cannot get subkey info from the registry", - retCode }; - } + // Retrieve information about the specified subkey + retCode = ::RegEnumKeyEx(keyHandle, index, nameBuffer.get(), &subKeyNameLen, + nullptr, // Reserved + nullptr, // No class information + nullptr, // No class size + nullptr // No last write time + ); - // Add the subkey name and type to the vector - subKeys.push_back( - std::make_pair(std::wstring{ nameBuffer.get(), subKeyNameLen }, 0)); + // Check if the subkey information retrieval was successful + if (retCode != ERROR_SUCCESS) { + // Close the key handle and handle the error + RegCloseKey(keyHandle); + throw RegistryError{"Cannot get subkey info from the registry", retCode}; } - // Close the key handle - RegCloseKey(keyHandle); + // Add the subkey name and type to the vector + subKeys.push_back( + std::make_pair(std::wstring{nameBuffer.get(), subKeyNameLen}, 0)); +} + +// Close the key handle +RegCloseKey(keyHandle); - // Return the vector containing subkey names and types - return subKeys; +// Return the vector containing subkey names and types +return subKeys; } std::vector> -RegistryHelper::RegEnumValues(HKEY hKey, const std::wstring& subKey) -{ +RegistryHelper::RegEnumValues(HKEY hKey, const std::wstring &subKey) { HKEY keyHandle; // Open the specified key (root key or subkey) @@ -235,8 +195,7 @@ RegistryHelper::RegEnumValues(HKEY hKey, const std::wstring& subKey) nullptr, // no subkey count nullptr, // no subkey max length nullptr, // no subkey class length - &valueCount, - &maxValueNameLen, + &valueCount, &maxValueNameLen, nullptr, // no max value length nullptr, // no security descriptor nullptr // no last write time @@ -245,8 +204,8 @@ RegistryHelper::RegEnumValues(HKEY hKey, const std::wstring& subKey) // Handle error, close the key handle and return RegCloseKey(keyHandle); throw RegistryError{ - "RegQueryInfoKey failed while preparing for value enumeration", retCode - }; + "RegQueryInfoKey failed while preparing for value enumeration", + retCode}; } maxValueNameLen++; @@ -258,10 +217,7 @@ RegistryHelper::RegEnumValues(HKEY hKey, const std::wstring& subKey) // Get the name and type DWORD valueNameLen = maxValueNameLen; DWORD valueType{}; - retCode = ::RegEnumValue(keyHandle, - index, - nameBuffer.get(), - &valueNameLen, + retCode = ::RegEnumValue(keyHandle, index, nameBuffer.get(), &valueNameLen, nullptr, // reserved &valueType, nullptr, // no data @@ -270,12 +226,12 @@ RegistryHelper::RegEnumValues(HKEY hKey, const std::wstring& subKey) if (retCode != ERROR_SUCCESS) { // Handle error, close the key handle and throw an exception RegCloseKey(keyHandle); - throw RegistryError{ "Cannot enumerate values: RegEnumValue failed", - retCode }; + throw RegistryError{"Cannot enumerate values: RegEnumValue failed", + retCode}; } valueInfo.push_back(std::make_pair( - std::wstring{ nameBuffer.get(), valueNameLen }, valueType)); + std::wstring{nameBuffer.get(), valueNameLen}, valueType)); } // Close the key handle @@ -283,3 +239,44 @@ RegistryHelper::RegEnumValues(HKEY hKey, const std::wstring& subKey) return valueInfo; } + +void RegistryHelper::RegSetDword(HKEY hKey, const std::wstring &subKey, + const std::wstring &value, DWORD data) { + m_errorCode = ::RegSetKeyValue(hKey, subKey.c_str(), value.c_str(), REG_DWORD, + &data, sizeof(data)); + if (m_errorCode != ERROR_SUCCESS) { + throw RegistryError("Cannot set DWORD value in registry.", m_errorCode); + } +} + +void RegistryHelper::RegSetString(HKEY hKey, const std::wstring &subKey, + const std::wstring &value, + const std::wstring &data) { + m_errorCode = ::RegSetKeyValue( + hKey, subKey.c_str(), value.c_str(), REG_SZ, data.c_str(), + static_cast((data.length() + 1) * sizeof(wchar_t))); + if (m_errorCode != ERROR_SUCCESS) { + throw RegistryError("Cannot set string value in registry.", m_errorCode); + } +} + +void RegistryHelper::RegSetMultiString(HKEY hKey, const std::wstring &subKey, + const std::wstring &value, + const std::vector &data) { + // Concatenate the strings and add an extra null character at the end + std::wstring multiString; + for (const auto &str : data) { + multiString += str; + multiString.push_back(L'\0'); + } + multiString.push_back(L'\0'); // Extra null character at the end + + m_errorCode = ::RegSetKeyValue( + + hKey, subKey.c_str(), value.c_str(), REG_MULTI_SZ, multiString.c_str(), + static_cast(multiString.length() * sizeof(wchar_t))); + if (m_errorCode != ERROR_SUCCESS) { + throw RegistryError("Cannot set multi-string value in registry.", + m_errorCode); + } +} diff --git a/RegistryHelper/RegistryHelper.h b/RegistryHelper/RegistryHelper.h index 68e8dcf..b88ccf5 100644 --- a/RegistryHelper/RegistryHelper.h +++ b/RegistryHelper/RegistryHelper.h @@ -5,14 +5,10 @@ #include #include -class RegistryError : public std::runtime_error -{ +class RegistryError : public std::runtime_error { public: - RegistryError(const char* message, LONG errorCode) - : std::runtime_error{ message } - , m_errorCode{ errorCode } - { - } + RegistryError(const char *message, LONG errorCode) + : std::runtime_error{message}, m_errorCode{errorCode} {} LONG ErrorCode() const noexcept { return m_errorCode; } @@ -20,30 +16,35 @@ class RegistryError : public std::runtime_error LONG m_errorCode; }; -class RegistryHelper -{ +class RegistryHelper { public: RegistryHelper(); - DWORD RegGetDword(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value); + DWORD RegGetDword(HKEY hKey, const std::wstring &subKey, + const std::wstring &value); - std::wstring RegGetString(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value); + std::wstring RegGetString(HKEY hKey, const std::wstring &subKey, + const std::wstring &value); std::vector RegGetMultiString(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value); + const std::wstring &subKey, + const std::wstring &value); - std::vector> RegEnumSubKeys( - HKEY hKey, - const std::wstring& subKey); + std::vector> + RegEnumSubKeys(HKEY hKey, const std::wstring &subKey); - std::vector> RegEnumValues( - HKEY hKey, - const std::wstring& subKey); + std::vector> + RegEnumValues(HKEY hKey, const std::wstring &subKey); + + void RegSetDword(HKEY hKey, const std::wstring &subKey, + const std::wstring &value, DWORD data); + + void RegSetString(HKEY hKey, const std::wstring &subKey, + const std::wstring &value, const std::wstring &data); + + void RegSetMultiString(HKEY hKey, const std::wstring &subKey, + const std::wstring &value, + const std::vector &data); private: LONG m_errorCode; // store the last error code diff --git a/UnitTest/TestRegistryHelper.cpp b/UnitTest/TestRegistryHelper.cpp index 650ed40..91f5f24 100644 --- a/UnitTest/TestRegistryHelper.cpp +++ b/UnitTest/TestRegistryHelper.cpp @@ -4,77 +4,70 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework; namespace RegistryHelperTests { - TEST_CLASS(RegistryHelperTests) { -public: - - TEST_METHOD(TestRegGetDword) { - RegistryHelper registryHelper; - HKEY hKey = HKEY_LOCAL_MACHINE; - std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; - std::wstring valueName = L"BootDriverFlags"; - - DWORD dwordValue = registryHelper.RegGetDword(hKey, subKey, valueName); - Assert::AreNotEqual(dwordValue, static_cast(0)); - } - - TEST_METHOD(TestRegGetString) - { - RegistryHelper registryHelper; - HKEY hKey = HKEY_LOCAL_MACHINE; - std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; - std::wstring valueName = L"CurrentUser"; - - std::wstring stringValue = - registryHelper.RegGetString(hKey, subKey, valueName); - Assert::IsFalse(stringValue.empty()); - } - - TEST_METHOD(TestRegGetMultiString) - { - RegistryHelper registryHelper; - HKEY hKey = HKEY_LOCAL_MACHINE; - std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; - std::wstring valueName = L"PreshutdownOrder"; - - std::vector multiStringValue = - registryHelper.RegGetMultiString(hKey, subKey, valueName); - Assert::IsFalse(multiStringValue.empty()); - } - - TEST_METHOD(TestRegEnumValues) - { - RegistryHelper registryHelper; - HKEY hKey = HKEY_LOCAL_MACHINE; - std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; - - try { - auto valueInfo = registryHelper.RegEnumValues(hKey, subKey); - - Assert::IsFalse(valueInfo.empty(), L"No values were enumerated."); - - Assert::AreEqual(L"BootDriverFlags", - valueInfo[0].first.c_str(), - L"Unexpected value name."); - Assert::AreEqual(REG_DWORD, valueInfo[0].second, L"Unexpected value type."); - - } - catch (const RegistryError&) { - Assert::Fail(L"Unexpected RegistryError exception"); - } - } - - TEST_METHOD(TestRegEnumSubKeys) - { - RegistryHelper registryHelper; - HKEY hKey = HKEY_LOCAL_MACHINE; - std::wstring subKey = L"SOFTWARE\\Microsoft"; - - std::vector> subKeys = - registryHelper.RegEnumSubKeys(hKey, subKey); - - Assert::IsFalse(subKeys.empty()); - Assert::AreEqual(static_cast(0), subKeys[0].second); - } - } - ; +TEST_CLASS(RegistryHelperTests){ + public : + + TEST_METHOD(TestRegGetDword){RegistryHelper registryHelper; +HKEY hKey = HKEY_LOCAL_MACHINE; +std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; +std::wstring valueName = L"BootDriverFlags"; + +DWORD dwordValue = registryHelper.RegGetDword(hKey, subKey, valueName); +Assert::AreNotEqual(dwordValue, static_cast(0)); +} // namespace RegistryHelperTests + +TEST_METHOD(TestRegGetString) { + RegistryHelper registryHelper; + HKEY hKey = HKEY_LOCAL_MACHINE; + std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; + std::wstring valueName = L"CurrentUser"; + + std::wstring stringValue = + registryHelper.RegGetString(hKey, subKey, valueName); + Assert::IsFalse(stringValue.empty()); +} + +TEST_METHOD(TestRegGetMultiString) { + RegistryHelper registryHelper; + HKEY hKey = HKEY_LOCAL_MACHINE; + std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; + std::wstring valueName = L"PreshutdownOrder"; + + std::vector multiStringValue = + registryHelper.RegGetMultiString(hKey, subKey, valueName); + Assert::IsFalse(multiStringValue.empty()); +} + +TEST_METHOD(TestRegEnumValues) { + RegistryHelper registryHelper; + HKEY hKey = HKEY_LOCAL_MACHINE; + std::wstring subKey = L"SYSTEM\\CurrentControlSet\\Control"; + + try { + auto valueInfo = registryHelper.RegEnumValues(hKey, subKey); + + Assert::IsFalse(valueInfo.empty(), L"No values were enumerated."); + + Assert::AreEqual(L"BootDriverFlags", valueInfo[0].first.c_str(), + L"Unexpected value name."); + Assert::AreEqual(REG_DWORD, valueInfo[0].second, L"Unexpected value type."); + + } catch (const RegistryError &) { + Assert::Fail(L"Unexpected RegistryError exception"); + } +} + +TEST_METHOD(TestRegEnumSubKeys) { + RegistryHelper registryHelper; + HKEY hKey = HKEY_LOCAL_MACHINE; + std::wstring subKey = L"SOFTWARE\\Microsoft"; + + std::vector> subKeys = + registryHelper.RegEnumSubKeys(hKey, subKey); + + Assert::IsFalse(subKeys.empty()); + Assert::AreEqual(static_cast(0), subKeys[0].second); +} +} +; }