Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Win7 IE9
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...
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 16-Sep-11 10:03am
Edited 16-Sep-11 10:09am
v3
Comments
Richard MacCutchan at 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 at 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 at 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 at 16-Sep-11 15:19pm
   
No, No Errors. Does the buffer need clearing?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Member 7766180 at 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 at 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.
Randor at 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 at 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 at 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"));
}
Member 7766180 at 16-Sep-11 18:47pm
   
Security Zone Settings Don't Work with WM_SETTINGCHANGE.
Randor at 16-Sep-11 18:57pm
   
As I stated previously using WM_SETTINGCHANGE to change these settings is undocumented and should probably be avoided. You do realize that virtual address pointing to the string only exists in the process calling the SendNotifyMessage function right? I reiterate my previous advice... you should probably use IInternetZoneManager::SetZoneActionPolicy() to modify these settings.
 
P.S. The format of these 'Quick Answers' is very awkward when we enter these lengthy discussions. The original question has already been addressed.
 
Best Wishes,
-David Delaune

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 16 Sep 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100