Option Explicit
Private Declare Function internetsetoption Lib "wininet.dll" Alias "InternetSetOptionA" _
(ByVal hinternet As Long, ByVal dwoption As Long, ByRef lpbuffer As Any, ByVal dwbufferlength As Long) As Long
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
Private Const HKEY_CURRENT_USER = &H80000001
Private Sub SetSurrogate(address As String, Port As String) '设置代理服务器的地址跟端口
Dim str As String
Dim SubKey As String
Dim hKey As Long
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
Private Sub SetEnable()
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
Private Sub SetDisable()
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, 0&, 4
RegCloseKey hKey
End Sub
Private Sub Command1_Click() '使代理服务器可用
SetSurrogate "125.88.75.151", "3128"
SetEnable
Call internetsetoption(0, 39, 0, 0)
End Sub
Private Sub Command2_Click() '使代理服务器不可用
SetDisable
Call internetsetoption(0, 39, 0, 0)
End Sub
Private Declare Function internetsetoption Lib "wininet.dll" Alias "InternetSetOptionA" _
(ByVal hinternet As Long, ByVal dwoption As Long, ByRef lpbuffer As Any, ByVal dwbufferlength As Long) As Long
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
Private Const HKEY_CURRENT_USER = &H80000001
Private Sub SetSurrogate(address As String, Port As String) '设置代理服务器的地址跟端口
Dim str As String
Dim SubKey As String
Dim hKey As Long
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
Private Sub SetEnable()
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
Private Sub SetDisable()
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, 0&, 4
RegCloseKey hKey
End Sub
Private Sub Command1_Click() '使代理服务器可用
SetSurrogate "125.88.75.151", "3128"
SetEnable
Call internetsetoption(0, 39, 0, 0)
End Sub
Private Sub Command2_Click() '使代理服务器不可用
SetDisable
Call internetsetoption(0, 39, 0, 0)
End Sub