IE 代理服务器设置程序实现

因为最近闲的要命.所以总喜欢去些BBS聊天室之类的地方打发时间可是.突然发现这些地方总是喜欢记录IP真是麻烦.别人一跟踪马上就查出你的位置.实在是不爽.所以.就只好设置代理服务器.IE的设置是带这个功能的.所以很简单.只要设置就可以了.不过,实在觉得.那样太简单了.所以就想自己做一个程序实现 。
可是没什么眉目.不过突然想到腾讯的浏览器也有类似功能.可是.整个程序才916K,所以不用说肯定是有动态连接库的协助的.既然如此.那么只用导出来看看就知道了.于是.使用dumpbin这个PE工具Imports一下就全明白了象其他程序一样.通常USER32,Kernel32.GDI32....这些都不是今天的主角.Wininet.Dll才是今天的主角.这里导出了.三个函数.其中InternetsetOption才是关键因素.在MSDN中很快查到了.所以一切都很顺利.该函数的重点参数在第二个参数上面dwOption.所以继续参考MSDN就知道了 。
INTERNET_OPTION_PROXY和INTERNET_OPTION_SETTINGS_CHANGED.第一个看名字也知道是设置代理.第二个是负责切换设置的.OK有了这些是否就OK了呢.是的基本OK不过不要忘记了这样做必须重启IE.因为IE也是依赖注册表地.所以去注册表找找.很快就明了.HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings几乎谁都知道的Internet设置键.没什么可说的.知道了这些下面程序来实现就简单了.因为根本没什么技术.只是调用API和写注册表 。
首先用Delphi来实现.delphi实现很简单.因为delphi的单元WinInet中就封装了该API调用的所有文档所以就简单多了.首先做一级面向对象的封装.一个对象TsetProxy,然后定义两个数据分别是代理主机和代理端口.然后一个负责调用的函数 。
代码如下:
unit Unit1;
interface
uses
Registry,WinInet
type
;TSetProxy=class
;private
{ Private declarations }
;procedure SetReg(FMProxy:string);
; public
;;; { Public declarations }
;;; Proxy: string;
;;; port:string;
;;; constructor Create(Proxy,Port:string);
;;; procedure SetProxy();
//;procedure SetProxy(const fProxy,fPort: string);
end;
implementation【IE 代理服务器设置程序实现】marqueesHeight=18;stopscroll=false;icefable1.scrollTop=0;with(icefable1){style.width=0;style.height=marqueesHeight;style.overflowX="visible";style.overflowY="hidden";noWrap=true;onmouseover=new Function("stopscroll=true");onmouseout=new Function("stopscroll=false");}preTop=0; currentTop=0; stoptime=0;function init_srolltext(){icefable2.innerHTML="";icefable2.innerHTML =icefable1.innerHTML;icefable1.innerHTML=icefable2.innerHTML icefable2.innerHTML;setInterval("scrollUp()",50);}function scrollUp(){if(stopscroll==true) return;currentTop =1;if(currentTop==19){stoptime =1;currentTop-=1;if(stoptime==50){currentTop=0;stoptime=0;}}else {preTop=icefable1.scrollTop;icefable1.scrollTop =1;if(preTop==icefable1.scrollTop){icefable1.scrollTop=icefable2.offsetHeight-marqueesHeight;icefable1.scrollTop =1;}}}init_srolltext();//实际设置代理
procedure TSetProxy.SetProxy;
var FProxy: string;
;Pinfo: INTERNET_PROXY_INFO;
begin
FProxy:=Format("%s:%s",[self.Proxy,self.port]);
Pinfo.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
Pinfo.lpszProxy := pchar(proxy);
InternetSetOption(nil, INTERNET_OPTION_PROXY, @Pinfo, SizeOf(PInfo));
InternetSetOption(nil, INTERNET_OPTION_SETTINGS_CHANGED, nil, 0);
self.SetReg(FProxy);
end;
//SetReg负责读写注册表
procedure TSetProxy.SetReg(FMProxy:string);
var
reg: Tregistry;
begin
reg:=Tregistry.Create;
; try
;reg.RootKey := HKEY_CURRENT_USER;
;if reg.OpenKey("SoftwareMicrosoftWindowsCurrentVersionInternet Settings", True) then
;begin
;;;reg.Writestring("ProxyServer", FMproxy);

推荐阅读