I have written a small C++ console application to set a Windows registry key. Specifically, I am changing the "Use a proxy server for your LAN" checkbox of the Internet Options dialog, shown below:
Here is the code that I'm using to set this key. I can confirm that the registry key updates successfully, and I can confirm that the dialog's checkbox also reflects these changes. However, the problem I'm having is that the effect is NOT actually taking place in the operating system.
const DWORD ENABLED_VALUE = 1;
const DWORD DISABLED_VALUE = 0;
const LPCWSTR REGISTRY_KEY_LOCATION = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
const LPCWSTR REGISTRY_KEY_NAME = TEXT("ProxyEnable");
PHKEY OpenRegistryKey(PHKEY key) {
LONG err = RegOpenKey(HKEY_CURRENT_USER, REGISTRY_KEY_LOCATION, key);
if (err != ERROR_SUCCESS) {
cout << "Unable to open registry key.\n";
}
return key;
}
void SetProxy(DWORD value) {
HKEY key;
OpenRegistryKey(&key);
LONG err = RegSetValueEx(key, REGISTRY_KEY_NAME, 0, REG_DWORD, (const BYTE*)&value, sizeof(value));
if (err != ERROR_SUCCESS) {
cout << "Unable to set registry value ProxyEnable.\n";
cout << err;
}
RegCloseKey(key);
}
So if I use the above code to enable the proxy server, the proxy is still not enabled despite verifying the update in both the registry and the dialog. However, if I simply open the dialog from the image above, verify the checkbox has changed, then simply click "OK", the change takes affect and the proxy status changes.
Testing if the proxy is actually enabled is easy since I do all my work on a VPN: if the proxy is actually enabled, I can browse the internet. If it's disabled, every attempt to hit a URL in the browser times out or produces an error.
So, it seems to me that I must be missing some sort of "confirm change" step where the change is propogated throughout the Windows environment. I have tried using RegFlushKey after making the registry update, but that didn't seem to change anything. How do I get my registry updates to actually be picked up by Windows?