Skip to content

Instantly share code, notes, and snippets.

@bryc
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryc/484341a498858f329c10 to your computer and use it in GitHub Desktop.
Save bryc/484341a498858f329c10 to your computer and use it in GitHub Desktop.
g++ 4.8.1 (mingw) - setting registry keys
windres reg.rc -O coff -o reg.res
g++ -c reg.cpp
g++ -o reg.exe reg.o reg.res
#include <windows.h>
#include <string>
#pragma GCC diagnostic ignored "-Wwrite-strings"
HKEY OpenKey (HKEY hRootKey, char strKey[]) {
HKEY hKey;
LONG nError = RegOpenKeyEx (hRootKey, strKey, 0, KEY_ALL_ACCESS, &hKey);
if (nError == ERROR_FILE_NOT_FOUND) {
RegCreateKeyEx (hRootKey, strKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
}
return hKey;
}
void SetVal (HKEY hKey, LPCTSTR lpValue, char data[], int lol) {
RegSetValueEx (hKey, lpValue, 0, REG_SZ, (LPBYTE)data, lol);
}
int main()
{
HKEY templ = OpenKey(HKEY_CLASSES_ROOT, ".");
HKEY handler = OpenKey(HKEY_CLASSES_ROOT, ".0069");
HKEY handler2 = OpenKey(handler, "ShellNew");
HKEY handler3 = OpenKey(handler2, "Config");
SetVal(templ, "", "Empty file", 10);
SetVal(handler, "", ".", 1);
SetVal(handler2, "NullFile", "", 0);
SetVal(handler2, "IconPath", "%SystemRoot%\\System32\\imageres.dll,2", 38);
SetVal(handler3, "NoExtension", "", 0);
return 0;
}
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.1.1.1"
processorArchitecture="X86"
name="reg.exe"
type="win32" />
<description>what does it matter</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
#include "winuser.h"
1 RT_MANIFEST "reg.exe.manifest"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment