Created
December 5, 2014 21:47
-
-
Save JubbaSmail/8e7283806e96b718af69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #if define UNICODE | |
| #define RegOpenKeyEx RegOpenKeyExW | |
| #define RegEnumKeyEx RegEnumKeyExW | |
| #else | |
| #define RegOpenKeyEx RegOpenKeyExA | |
| #define RegEnumKeyEx RegEnumKeyExA | |
| #endif | |
| #define MAX_KEY_LENGTH 255 | |
| HKEY Open(HKEY root,LPTSTR path, REGSAM permission) | |
| { | |
| HKEY hKey; | |
| LONG lResult = RegOpenKeyEx( | |
| root, //HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER | |
| path, // the path of the key | |
| 0, // must be 0 | |
| permission, //KEY_WRITE, KEY_READ, KEY_ALL_ACCESS, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS | |
| &hKey // OUT : The result [pass by refrence] | |
| ); | |
| if (lResult == ERROR_SUCCESS) | |
| return hKey; | |
| return INVALID_HANDLE_VALUE; | |
| } | |
| void Close(HKEY hKey) | |
| { | |
| RegCloseKey(hKey); | |
| } | |
| void ListKeys(HKEY hKey) | |
| { | |
| DWORD index = 0, SubKNameLen = MAX_KEY_LENGTH; | |
| CHAR SubKName[MAX_KEY_LENGTH]; | |
| while (ERROR_SUCCESS == RegEnumKeyEx(hKey, //Opned key to a specific path | |
| index, // incremental counter | |
| SubKName, // OUT : return key name | |
| &SubKNameLen, // IN max key lenght & OUT : return key length | |
| NULL, // Reserved | |
| NULL, // OUT : class name | |
| NULL, // IN : max class length & OUT : class length | |
| NULL //Last Write Time | |
| )) | |
| { | |
| printf("%s\n", SubKName); | |
| SubKNameLen = MAX_KEY_LENGTH; | |
| index++; | |
| } | |
| } | |
| int main() | |
| { | |
| HKEY hKey = Open(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer", KEY_ALL_ACCESS); | |
| if (hKey != INVALID_HANDLE_VALUE) | |
| { | |
| //do your job | |
| ListKeys(hKey); | |
| } | |
| Close(hKey); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment