Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code that edits the windows registry. It works fine when the setting is set to enable and I run the following code to disable...
C++
HKEY hKey; DWORD buffersize = 1024; DWORD dwErr = NO_ERROR; 
#define BUFFER_SIZE 1024
dwErr = RegOpenKeyEx (HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3",NULL,KEY_SET_VALUE|KEY_QUERY_VALUE,&hKey);
	if(ERROR_SUCCESS == dwErr)
	{
	BYTE data[BUFFER_SIZE] = {0};
	DWORD dwType = REG_NONE;
	dwErr = RegQueryValueExW(hKey,L"1803",NULL,&dwType,data,&buffersize);
		if(ERROR_SUCCESS == dwErr && REG_DWORD == dwType)
                {
		*((LPDWORD)data) = 3; //0 is Enable 3 is Disable
		dwErr = RegSetValueExW(hKey,L"1803",0,REG_DWORD,data,sizeof(DWORD));
		}
		RegCloseKey (hKey);
		}

However when I try to switch this line *((LPWORD)data) = 0;
It doesn't change from disabled to enabled. Perhaps I have to clear the BUFFER? Any suggestions welcomed. Thank you.
Posted
Updated 16-Sep-11 9:09am
v3
Comments
Richard MacCutchan 16-Sep-11 15:09pm    
What is it that is enabled or disabled? Did you check that the change has actually been made to the registry?
Member 7766180 16-Sep-11 15:11pm    
Yes I did check the registry and 0 will change to 3 but I can't get 3 to change to 0.
Marc A. Brown 16-Sep-11 15:14pm    
Any error? Or does it just silently fail? If it generates an error, you should add that to the question.
Member 7766180 16-Sep-11 15:19pm    
No, No Errors. Does the buffer need clearing?

1 solution

The code works. If you are using regedit to view the changes then you need to select View->Refresh() from the menu to see the changes.

A quick note... this registry key changes an internet security setting for Microsoft Trident based browsers at zone 3 (Internet Zone). You will most likely need to send a WM_SETTINGCHANGE message to the HWND_BROADCAST handle to notify applications that a setting has been changed.

Best Wishes,
-David Delaune
 
Share this answer
 
Comments
Member 7766180 16-Sep-11 17:03pm    
Thank you. I got it to change the setting now, it was a timing isuue. However: I think you have a point because, 1)I know your really smart(from your post) and 2)After I make the change it says that the webpage is busy if I try to move away from it. And if I do, It won't let me download even though the registry says that it's ok. So it must be in WM_SETTINGCHANGE that I am missing. How would one accomplish this? I've done a search and I am more confused than ever. I just want to tell explorer that the setting has been changed I will continue to search...but any help is more than welcome. Thank you.
Member 7766180 16-Sep-11 17:12pm    
Something like this?
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0xF2, 0)
OR
DWORD dwResult;
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
SPI_SETDOUBLECLICKTIME, 0,
SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG,
5000, &dwResult);
OR
SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE,
SPI_SETDOUBLECLICKTIME, 0);


But is it possible just to notify explorer because that is relly the only app being affected.
[no name] 16-Sep-11 17:42pm    
Hi,

I believe the hidden Internet Explorer window responds to a WM_SETTINGCHANGE message but I also think the the parameters are undocumented. I believe the LPARAM should be a pointer to a string containing the registry path if I remember correctly. You should probably just scrap all of this code and instead use IInternetZoneManager::SetZoneActionPolicy() to change this setting.

Best Wishes,
-David Delaune
Member 7766180 16-Sep-11 17:47pm    
OK got this. But would I need to do WM_SETTINGCHANGE yet?
HRESULT SetZoneActionPolicy(
[in] DWORD dwZone,
[in] DWORD dwAction,
[in] BYTE *pPolicy,
[in] DWORD cbPolicy,
[in] URLZONEREG urlZoneReg
);
Also, having what I have, what values would go where? Thanks!
Member 7766180 16-Sep-11 18:40pm    
I did this for the message ut so far I can only change it once, after that Explorer hangs. "Window Is Busy"

HKEY hKey; DWORD buffersize = 1024; DWORD dwErr = NO_ERROR;
#define BUFFER_SIZE 1024
dwErr = RegOpenKeyEx (HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3",NULL,KEY_SET_VALUE|KEY_QUERY_VALUE,&hKey);
if(ERROR_SUCCESS == dwErr)
{
BYTE data[BUFFER_SIZE] = {0};
DWORD dwType = REG_NONE;
dwErr = RegQueryValueExW(hKey,L"1803",NULL,&dwType,data,&buffersize);
if(ERROR_SUCCESS == dwErr && REG_DWORD == dwType)
{
*((LPDWORD)data) = 3; //0 is Enable 3 is Disable
dwErr = RegSetValueExW(hKey,L"1803",0,REG_DWORD,data,sizeof(DWORD));
}
RegCloseKey (hKey);
SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3"));
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900