Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Arteiii authored Feb 12, 2024
2 parents 8fafe07 + a0c094b commit 4cb6b76
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 262 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ClangFormat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ jobs:
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git diff --exit-code || (git add -A && git commit -m "Auto-fix formatting issues")
git push
git push
1 change: 1 addition & 0 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 54 additions & 58 deletions Example/main.cpp
Original file line number Diff line number Diff line change
@@ -1,74 +1,70 @@
#include "RegistryHelper.h"
#include <iostream>

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<std::wstring> multiStringValue =
registryHelper.RegGetMultiString(hKey, subKey, valueNameMultiString);
std::vector<std::wstring> 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<std::pair<std::wstring, DWORD>> subKeys = registryHelper.RegEnumSubKeys(hKey, subKey);
//
// Example 4: Enumerate sub-keys
//
std::vector<std::pair<std::wstring, DWORD>> 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<std::pair<std::wstring, DWORD>> values = registryHelper.RegEnumValues(hKey, subKey);
//
// Example 5: Enumerate values
//
std::vector<std::pair<std::wstring, DWORD>> 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;
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ std::vector<std::pair<std::wstring, DWORD>> subKeys =
// Example 5: Enumerate values
std::vector<std::pair<std::wstring, DWORD>> 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.
Expand Down
Loading

0 comments on commit 4cb6b76

Please sign in to comment.