在程序中动态的配置ie代理,我用了如下方法:
public static void SetProxy()
{
//打开注册表
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
//Microsoft\
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath,true);
//更改健值,设置代理,ProxyServer
optionKey.SetValue("ProxyEnable",1);
optionKey.SetValue("ProxyServer","127.1.0.22:80"); //激活代理设置
InternetSetOption(0,39,IntPtr.Zero,0);
InternetSetOption(0,37,IntPtr.Zero,0);
}这样仅能改变ie的局域网设置的代理选项,现在还要也能改变拨号的代理,不知怎么做,请高手指点.
public static void SetProxy()
{
//打开注册表
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
//Microsoft\
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath,true);
//更改健值,设置代理,ProxyServer
optionKey.SetValue("ProxyEnable",1);
optionKey.SetValue("ProxyServer","127.1.0.22:80"); //激活代理设置
InternetSetOption(0,39,IntPtr.Zero,0);
InternetSetOption(0,37,IntPtr.Zero,0);
}这样仅能改变ie的局域网设置的代理选项,现在还要也能改变拨号的代理,不知怎么做,请高手指点.
可以参考http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetdial.asp
http://www.windowsdevcenter.com/pub/a/oreilly/windows/news/dialup_0600.htmlhttp://www.developerfusion.co.uk/forums/thread/94059/#94059http://webdesign.ittoolbox.com/groups/technical-functional/csharp-l/562475#
Private Shared Function UrlMkSetSessionOption(ByVal dwOption As Integer, ByVal pBuffer As String, _
ByVal dwBufferLength As Integer, ByVal dwReserved As Integer) As Integer
End Function<DllImport("urlmon.dll", CharSet:=CharSet.Ansi)> _
Private Shared Function UrlMkGetSessionOption(ByVal dwOption As Integer, ByVal pBuffer As StringBuilder, ByVal dwBufferLength As Integer, _
ByRef pdwBufferLength As Integer, ByVal dwReserved As Integer) As Integer
End Function
http://www.mentalis.org/soft/projects/proxy/
大概是这样的
1. 发送 INTERNET_OPTION_PER_CONNECTION_OPTION 到 InternetSetOption
2. 发送 INTERNET_OPTION_SETTINGS_CHANGED 到 InternetSetOption
3. 发送 INTERNET_OPTION_REFRESH 到 InternetSetOption在1中至少构造两个INTERNET_PER_CONN_OPTION[] options = new INTERNET_PER_CONN_OPTION[2];
options[0] = new INTERNET_PER_CONN_OPTION();
options[0].dwOption = Wininet.INTERNET_PER_CONN_FLAGS;
options[0].Value.dwValue = Wininet.PROXY_TYPE_DIRECT | Wininet.PROXY_TYPE_PROXY; options[1] = new INTERNET_PER_CONN_OPTION();
options[1].dwOption = Wininet.INTERNET_PER_CONN_PROXY_SERVER;
options[1].Value.pszValue = Marshal.StringToHGlobalAnsi(proxySever);打字好累,自己先试试吧,不行留油箱.