c++ - Registry functions not working under some circumstances -
i need programmatically disable windows error reporting in c++ application. this, want edit windows registry , write 2 values it.
the following code works on 32 bit windows 7 machine:
#include <stdio.h> #include <windows.h> void disablewer() { hkey key; printf("%d\n", regopenkey(hkey_local_machine, text("software\\microsoft\\windows\\windows error reporting\\"), &key)); dword val = 1; printf("%d\n", regsetvalueex(key, text("disable"), 0, reg_dword, (const byte*)&val, sizeof(val))); regclosekey(key); } int main() { disablewer(); printf("%d\n", getlasterror()); getchar(); }
both functions succeed (return error_success), getlasterror() prints 0, , required value set in registry.
on vps program output same, registry isn't modified - nothing happens. can set value manually using regedit, presume it's not privilege related problem. vps runs windows server 2008 r2, 64-bit.
what reason? possible vps host's configuration interfering windows api?
if error_success know function succeeded , registry in fact updated. not use getlasterror() @ all, registry api doesn't use it.
you looking in wrong place change, 32-bit process gets redirected on 64-bit operating system. first place under hklm\software\wow6432node registry key.
build program target x64 avoid redirection or use key_wow64_64key option in regopenkeyex(). program must run elevated able modify key, use appropriate manifest entry (requireadministrator) activate uac prompt. sysinternals' process monitor utility excellent troubleshoot registry access problems.
Comments
Post a Comment