如何用VB设置IE代理IP并且马上生效?
为什么用VB改注册表,原本开着的IE窗口的网页打开www.ip138.com却IP没变,多设置几次IP也是没变,只对新开的IE窗口有效,设置一次IP,要新开一个IE窗口才行,有什么办法能不关IE窗口就能生效?
在IE上点INTERTNET 选项,再点连接,再点局域网设置,这样去设置的话,每次设置都是有效的,并且VB中的WEBBROWSER控件中的IP也会跟着改动,这个用IE开www.ip138.com和VB中webbrowser1的网址设成www.ip138.com。刷新一下就能看到效果
代码如下,看看什么原因?
以前看到是说要用sendmessage发送一个什么全局消息,不知是不是有用?
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Const REG_DWORD As Long = 4
Private Const REG_SZ = 1
Const HKEY_CURRENT_USER = &H80000001
Sub 注册表设置IE代理(IPport As String) '设置代理服务器的地址跟端口
If IPport = "" Then Exit Sub
Dim str As String
Dim SubKey As String
Dim hKey As Long
Dim address As String, port As String
Dim sz
sz = Split(IPport, ":")
address = sz(0)
port = sz(1)
str = Trim(address) & ":" & Trim(port)
SubKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
RegSetValueEx hKey, "ProxyServer", 0, REG_SZ, ByVal str, LenB(StrConv(str, vbFromUnicode)) + 1
RegCloseKey hKey
End Sub
Sub 启用IE代理()
Dim SubKey As String
Dim hKey As Long
SubKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
RegSetValueEx hKey, "ProxyEnable", 0, REG_DWORD, 1&, 4
RegCloseKey hKey
End Sub