怎样设置IE中的代理服务器(程序运行后自动改),谢谢大家,在线等!

shuangshuang_zhu 2006-10-24 11:39:22
我想在我的程序里加一个功能:程序启动时就要将internet设置中的代理服务器改变,HTTP:localhost:8080,HTTPS=localhost:8080.
请大家帮帮忙,谢谢你们!
...全文
355 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
palmax 2006-10-24
  • 打赏
  • 举报
回复
在线等的依例纯顶不看
shuangshuang_zhu 2006-10-24
  • 打赏
  • 举报
回复
我在网上找到一个别人写的函数,
BOOL CMy3Dlg::SetProxy(CString ip, UINT port)
{
CString l_just;
// l_just.Format("http=%s:%d;https=%s:%d", ip.LockBuffer(), port,ip.LockBuffer(), port);
l_just.Format("http=%s:%d", ip.LockBuffer(), port);


//下面的代码将注册表项HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer
//的内容取出来
HKEY hKeyOut;
if( ERROR_SUCCESS != RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
0, KEY_CREATE_LINK | KEY_WRITE | KEY_READ | KEY_NOTIFY|KEY_QUERY_VALUE , &hKeyOut))
{
return FALSE;
}


ULONG regsize = 0;
if(ERROR_SUCCESS != RegQueryValueEx(hKeyOut, "ProxyServer", NULL, NULL, NULL, ®size))
{
return FALSE;
}

LPBYTE pValue = new BYTE[regsize];
memset(pValue, 0x00, regsize);

if(ERROR_SUCCESS != RegQueryValueEx(hKeyOut, "ProxyServer", NULL, NULL, pValue,®size))
{
return FALSE;
}

CString oldproxy((char *)pValue);
delete [] pValue;
pValue = NULL;

//从注册表中读出来的数据格式为:http=111.111.111.111:80;ftp=222.222.222.222:21;......,
//如果你只想改变http的代理的话, 就只要把其中的111.111.111.111:80换成你想要的代理就行了,
//类似的你可以改变其他的代理.

//下面的代码就替换http代理成为参数所指定的代理.
int pos = 0;
//如果没有字符串中没有找到"http="说明用户没有设置http代理,这时候直接加在最前面.
if(-1 == (pos = oldproxy.Find("http=")))
{
pos = 0;
}

int pos1 = 0;
if(-1 == (pos1 = oldproxy.Find(";", pos)))
{
pos1 = oldproxy.GetLength();
}

oldproxy.Delete(pos, pos1 - pos);
oldproxy.Insert(pos, l_just);

/*
int pos2 = 0;
//如果没有字符串中没有找到"http="说明用户没有设置http代理,这时候直接加在最前面.
if(-1 == (pos = oldproxy.Find("https=")))
{
pos2 = pos1;
}

int pos3 = 0;
if(-1 == (pos3 = oldproxy.Find(";", pos2)))
{
pos3 = oldproxy.GetLength();
}
l_just.Format("https=%s:%d", ip.LockBuffer(), port);

oldproxy.Delete(pos2, pos3 - pos2);
oldproxy.Insert(pos2, l_just);

*/
if(ERROR_SUCCESS != RegSetValueEx(hKeyOut, "ProxyServer", 0, REG_SZ, (const unsigned char *)oldproxy.LockBuffer(), oldproxy.GetLength() + 1))
{
return FALSE;
}

RegCloseKey(hKeyOut);


//使设置生效
if(!InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0))
{
return FALSE;
}


return TRUE;
}
能改HTTP,但是问题是,我要在Internet选项-》连接-》局域网设置-》HTTP 里面先赋个初始值 才能改,我想在程序运行 调用了这个函数之后就自动改,大家看看还有什么好办法。谢谢大家,真诚等待大家帮助!
shuangshuang_zhu 2006-10-24
  • 打赏
  • 举报
回复
问题已经解决了,还是谢谢大家的关注。
shuangshuang_zhu 2006-10-24
  • 打赏
  • 举报
回复
那我不在线等,行不?呵呵

15,975

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧