Skip to content

Instantly share code, notes, and snippets.

@JubbaSmail
Created December 5, 2014 21:46
Show Gist options
  • Select an option

  • Save JubbaSmail/43ebd3c746f564d93692 to your computer and use it in GitHub Desktop.

Select an option

Save JubbaSmail/43ebd3c746f564d93692 to your computer and use it in GitHub Desktop.
#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