Created
December 5, 2014 21:46
-
-
Save JubbaSmail/43ebd3c746f564d93692 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 | |
| #else | |
| #define RegOpenKeyEx RegOpenKeyExA | |
| #endif | |
| 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 // The result [pass by refrence] | |
| ); | |
| if (lResult == ERROR_SUCCESS) | |
| return hKey; | |
| return INVALID_HANDLE_VALUE; | |
| } | |
| void Close(HKEY hKey) | |
| { | |
| RegCloseKey(hKey); | |
| } | |
| int main() | |
| { | |
| HKEY hKey = Open(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", KEY_ALL_ACCESS); | |
| if (hKey != INVALID_HANDLE_VALUE) | |
| { | |
| //do your job | |
| printf("Key Opned..."); | |
| } | |
| Close(hKey); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment