lundi 30 mars 2015

Internet explorer fix connection error

I have an application that creates some entries in the IE(Internet explorer) under LAN settings in the use automatic configuration script.


Now when my application exits. It deletes the entries it made and only the default or older text should be there. In order to achieve this first I am copying the value from registry before my application makes any entries by using RegQueryValueEx(hKey,L"AutoConfigURL",NULL,NULL,(BYTE*)buffer,&dwBufLen) and copying the value of AutoConfigURLfrom here to other place in registry.(I am creating new entries in registry for this). Post when my application exits I copy the AutoConfigURL string from the place where i backed up and restore back to IE settings. below is my code.:



bool Timeout::CopyRegistryProxySettings(HKEY hKeyRoot, LPCWSTR lpSubKey)
{
wchar_t buffer[MAX_PATH];
DWORD dwBufLen;
DWORD dwValue ;
DWORD dwDataSize = sizeof(DWORD);
memset(buffer, 0, sizeof buffer);
dwBufLen = MAX_PATH;
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\BackupSettings\\Internet Settings", 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
if( ERROR_SUCCESS ==
RegGetValue(HKEY_CURRENT_USER, L"Software\\BackupSettings\\Internet Settings", L"AutoConfigURL", RRF_RT_REG_SZ, NULL, NULL, NULL))
{
if(ERROR_SUCCESS == RegQueryValueEx(hKey,L"AutoConfigURL",NULL,NULL,(BYTE*)buffer,&dwBufLen))
{
int len= lstrlen(buffer);
buffer[len+1]='\0';
int len1= sizeof(buffer);
lstrcpy(AutoConfigURL,buffer);
memset(buffer, 0, sizeof buffer);

}

}

return 1;
}

bool Timeout::RestoreNewRegistry (HKEY hKeyRoot, LPCWSTR Subkey)
{
HKEY hKey;
DWORD size = 0;
DWORD type;
DWORD data = 0;

if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
if( ERROR_SUCCESS ==
RegGetValue(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", L"AutoConfigURL", RRF_RT_REG_SZ, NULL, NULL, NULL))
{
RegSetValueEx(hKey, L"AutoConfigURL", NULL,REG_SZ,(BYTE*)AutoConfigURL, (DWORD)((lstrlen(AutoConfigURL)+1)*sizeof(TCHAR)));
}
}
return 1;
}


Now everything works as expected but the problem is that after running my application when i open IE it shows the error Page cannot be displayed .Please check the connection settings. I cross verified all the entries in the registry are correct post running the application but still facing this issue.


Any work around for this.? Do we have any Windows API that can take back up of the registry and restore it back without copying the individual sub key values. What are the places in the registry where I should look for IE settings. For the above problem. Sorry if I made any mistake in asking question. Thanks In advance for help.


Aucun commentaire:

Enregistrer un commentaire