I need to programmatically disable Windows Error Reporting in my C++ application. To do this, I want to edit the Windows Registry and write two values to it.
The following code works perfectly on my 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, and the required value is set in the registry.
On my VPS the program output is the same, but the registry isn't actually modified - simply nothing happens. I can set the value manually using regedit, so I presume it's not a privilege related problem. The VPS runs Windows Server 2008 R2, 64-bit.
What could be the reason? Is it possible that the VPS host's configuration is interfering with the Windows API?