- //引用网上的一篇文章进行的修改 ,2003的所在注册表位置和其他的系统位置不同
- //hkey 是注册表主键,如HKEY_LOCAL_MACHINE,szUrl为IP地址(原文中有域名的添加方法,这里去掉了)
- BOOL VengFuncConfig::SetTrustfulUrl(HKEY hKey, TCHAR *szUrl, DWORD dwType,BOOL IsWindow2003)
- {
- HKEY hkResult;
- int rc = 0;
- TCHAR szProtocol[MAX_PATH] = {0};
- TCHAR szRegPath[MAX_PATH] = {0};
- lstrcpy(szProtocol, _T("*"));
- //lstrcpy(szProtocol, _T("http"));
- CString cQueryIERegName = (IsWindow2003?_T("EscRanges"):_T("Ranges"));
- //判断是IP还是域名
- //IP类站点添加
- DWORD dwKeys = 0;
- wsprintf(szRegPath, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\%s"),cQueryIERegName);
- rc = RegCreateKey(hKey, szRegPath, &hkResult);
- //先获取该key下有多少个项
- rc = RegQueryInfoKey(hkResult, NULL, NULL, NULL, &dwKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
- RegCloseKey(hkResult);
- hkResult = NULL;
- if (rc != ERROR_SUCCESS)
- {
- return FALSE;
- }
- else
- {
- //查询当前的远程服务器IP是否加入了IE的受信任列表中
- wsprintf(szRegPath, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\%s\\Range%d"),cQueryIERegName ,dwKeys+10 -1);
- CString cHostIP = ReadCfg(_T(":Range"),szRegPath);
- if ( !cHostIP.CompareNoCase(szUrl) )
- {
- return FALSE;
- }
- wsprintf(szRegPath, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\%s\\Range%d"),cQueryIERegName, dwKeys+10);
- rc = RegCreateKey(hKey, szRegPath, &hkResult);
- //必须要先创建DWORD值,再创建字符串值,否则不能在Internet选项中信任站点列表中显示
- RegSetValueEx(hkResult, szProtocol, NULL, REG_DWORD, (BYTE *)&dwType, sizeof(DWORD));
- RegSetValueEx(hkResult, _T(":Range"), NULL, REG_SZ, (LPBYTE)szUrl, (lstrlen(szUrl)+1)*sizeof(TCHAR));
- RegCloseKey(hkResult);
- //使注册表修改立即生效
- //SystemParametersInfo(SPI_SETCURSORS,0,NULL,SPIF_SENDCHANGE || SPIF_UPDATEINIFILE);
- SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
- hkResult = NULL;
- }
- return TRUE;
- }