WebBrowser代理,如下!
INTERNET_OPEN_TYPE_PRECONFIG 不使用代理
{ access types for InternetOpen }
const
INTERNET_OPEN_TYPE_PRECONFIG = 0; { use registry configuration }
{$EXTERNALSYM INTERNET_OPEN_TYPE_PRECONFIG}
INTERNET_OPEN_TYPE_DIRECT = 1; { direct to net }
{$EXTERNALSYM INTERNET_OPEN_TYPE_DIRECT}
INTERNET_OPEN_TYPE_PROXY = 3; { via named proxy }
{$EXTERNALSYM INTERNET_OPEN_TYPE_PROXY}
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4; { prevent using java/script/INS }
{$EXTERNALSYM INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY}
请高手讲讲返回值i和当前代理设置的关系.
我现在只知道i=12时IE不使用代理!
1:INTERNET_STATE_CONNECTED :$00000001 连接状态;
INTERNET_STATE_DISCONNECTED :$00000002 非连接状态(和 INTERNET_STATE_CONNECTED 对应);
INTERNET_STATE_DISCONNECTED_BY_USER :$00000010 用户请求的非连接状态
INTERNET_STATE_IDLE :$00000100 连接状态,并且空闲
INTERNET_STATE_BUSY :$00000200 连接状态,正在响应连接请求
如:InternetQueryOption(nil, INTERNET_OPTION_CONNECTED_STATE, @ConnectState, StateSize)
InternetQueryOption 函数的检测结果只能表明当前的Internet设置是可用的,并不能表示计算机一定能访问Internet。
其INTERNET_OPTION_PROXY参数对应的具体值不同!
其实你可以使用InternetGetConnectedState,包含参数如下:
INTERNET_CONNECTION_MODEM 本地机器通过MODEM连接Internet
INTERNET_CONNECTION_LAN 本地机器通过局域网连接Internet
INTERNET_CONNECTION_PROXY 本地机器通过代理连接Internet
INTERNET_CONNECTION_MODEM_BUSY 本地机器的MODEM BUSY无法连接Internet
如:
var Flags, Reserved : DWORD
begin . . . .
Reserved := 0;
if InternetGetConnectedState( Flags, Reserved ) then
begin
if (Flags or INTERNET_CONNECTION_MODEM)
procedure TForm1.Button1Click(Sender: TObject);
var
info : INTERNET_PROXY_INFO;
reg : TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey:=HKEY_CURRENT_USER;
if reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Internet Settings',False) then
begin
reg.Writestring('ProxyServer','172.23.23.23:8888');
reg.Writestring('ProxyEnable', '1');
end;
reg.CloseKey;
reg.Free;
info.dwAccessType:=INTERNET_OPEN_TYPE_PROXY;
info.lpszProxy:='172.23.23.23:8888';
InternetSetOption(nil,INTERNET_OPTION_PROXY,@info,1000);
InternetSetOption(nil,INTERNET_OPTION_REFRESH, nil,0);
InternetSetOption(nil,INTERNET_OPTION_SETTINGS_CHANGED, nil,0);
end;
另外是否开机自动启动放到程序界面可以设置,不要不声不响的设置成开机自动启动!
来自:dage111, 时间:2005-7-10 8:21:04, ID:3129602
WebBrowser代理,和IE共同使用代理的.
也可以用下面的函数切换代理.
user urlmon,wininet;
procedure qiehuanproxy(const proxyname:string);
var info:TInternetProxyInfo;
lngth:integer;
h:integer;
proxy :pChar;
bypass :PChar;
begin
proxy:=pchar(proxyname);//proxy address:port
bypass:=pChar('');
info.dwAccessType := INTERNET_OPEN_TYPE_PROXY ;
info.lpszProxy :=proxy;
info.lpszProxyBypass:=bypass;
lngth:=sizeof(info);
h:=UrlMkSetSessionOption(INTERNET_OPTION_PROXY ,@info,lngth,0);
end
我的测试
procedure TForm1.Button2Click(Sender: TObject);
var
info:TInternetProxyInfo;
lngth:integer;
h:integer;
proxy :pChar;
bypass :PChar;
FTUserName,FTPassword:string;
hSession, hConnect, hRequest: hInternet;
begin
WebBrowser1.Navigate('about:blank');
FTUserName:='user1';
FTPassword:='123456' ;
proxy:='192.168.0.29:808';
bypass:=pChar('');
info.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
info.lpszProxy :=proxy;
info.lpszProxyBypass:=bypass;
//info.lpszProxyBypass:=nil;
lngth:=sizeof(info);
InternetSetOption(hRequest,INTERNET_OPTION_PROXY_USERNAME,PAnsiChar(FTUserName),Length(FTUserName)+1);
InternetSetOption(hRequest,INTERNET_OPTION_PROXY_PASSWORD,PAnsiChar(FTPassword),Length(FTPassword)+1);
InternetSetOption(nil, INTERNET_OPTION_PROXY, @info, SizeOf(Info));
//InternetSetOption(nil, INTERNET_OPTION_SETTINGS_CHANGED, nil, 0);
WebBrowser1.Navigate(Trim(edit1.Text));
end;
其他资料:
http://www.pcdog.com/p/html/20041218/181220045367_1.htm
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
//实际设置代理
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( '/Software/Microsoft/Windows/CurrentVersion/Internet Settings ', True) then
begin
reg.Writestring( 'ProxyServer ', FMproxy);
reg.WriteInteger( 'ProxyEnable ', integer(true));
end
finally
reg.CloseKey;
reg.free;
end;
end;
constructor TSetProxy.Create(Proxy,Port:string);
begin
self.Proxy:=Proxy;
self.port:=Port;
end;
end.
转自超级猛料
==========================================
更改IE代理服务器设置,不重新启动IE,代码如下:
但如何设置某种协议为一特定地址呢,BYPASS参数怎么用?
其实在proxyserver中http=205.207.118.51:80;https=205.207.118.51:80;gopher=205.207.118.51:80;socks=205.207.118.51:80是分别设置,如果只有地址和端口则是所有协议使用相同地址
///Coder:Kingron
function ChangeProxy(const Proxy, Port,ByPass: string; const bEnabled: boolean = True): boolean;
var
reg: Tregistry;
info: INTERNET_PROXY_INFO;
Fproxy:string;
begin
Result := False;
FProxy:=Format( '%s:%s ',[Proxy,Port]);
reg := Tregistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKey( '/Software/Microsoft/Windows/CurrentVersion/Internet Settings ', True) then
begin
reg.Writestring( 'ProxyServer ', Fproxy);
reg.WriteInteger( 'ProxyEnable ', integer(bEnabled));
info.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
info.lpszProxy := pchar(proxy);
info.lpszProxyBypass := pchar(ByPass);
InternetSetOption(nil, INTERNET_OPTION_PROXY, @info, SizeOf(Info));
InternetSetOption(nil, INTERNET_OPTION_SETTINGS_CHANGED, nil, 0);
// InternetSetOption(nil, INTERNET_OPTION_REFRESH, nil, 0);
// Sendmessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
Result:=True;
end
finally
reg.CloseKey;
reg.free;
end;
end;