Option Explicit
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (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 Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_DWORD = 4 ' 32-bit number
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const INTERNET_OPTION_SETTINGS_CHANGED = 39
Private Const INTERNET_OPTION_PROXY = 38
Private Declare Function InternetSetOption Lib "wininet.dll" Alias "InternetSetOptionA" (ByVal hInternet As Long, ByVal dwOption As Long, lpBuffer As Any, ByVal dwBufferLength As Long) As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const ReGApPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Private Type INTERNET_PROXY_INFO
dwAccessType As Long
lpszProxy As String
lpszProxyBypass As String
End Type
Sub SetReG(ByVal PEv As Long, ByVal PS As String)
Dim hKey As Long
Dim i As Long
i = RegOpenKey(HKEY_CURRENT_USER, ReGApPath, hKey)
i = RegSetValueEx(hKey, ByVal "ProxyServer", 0, REG_SZ, ByVal PS, ByVal LenB(PS))
i = RegSetValueEx(hKey, ByVal "ProxyEnable", 0, REG_DWORD, PEv, LenB(PEv))
i = RegCloseKey(hKey)
Call InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, "", 0)
End Sub
Sub iEsate(IPDRES As String)
Dim ConInfo As INTERNET_PROXY_INFO, lRetValue As Long
ConInfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY
ConInfo.lpszProxy = IPDRES 'IP地址:端口,例如:192.168.1.1:8080
ConInfo.lpszProxyBypass = ""
Call InternetSetOption(0, INTERNET_OPTION_PROXY, ConInfo, LenB(ConInfo))
End Sub
Private Sub Command1_Click()
SetReG 1, "88.23.3.6:80"
End Sub
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (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 Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_DWORD = 4 ' 32-bit number
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const INTERNET_OPTION_SETTINGS_CHANGED = 39
Private Const INTERNET_OPTION_PROXY = 38
Private Declare Function InternetSetOption Lib "wininet.dll" Alias "InternetSetOptionA" (ByVal hInternet As Long, ByVal dwOption As Long, lpBuffer As Any, ByVal dwBufferLength As Long) As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const ReGApPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Private Type INTERNET_PROXY_INFO
dwAccessType As Long
lpszProxy As String
lpszProxyBypass As String
End Type
Sub SetReG(ByVal PEv As Long, ByVal PS As String)
Dim hKey As Long
Dim i As Long
i = RegOpenKey(HKEY_CURRENT_USER, ReGApPath, hKey)
i = RegSetValueEx(hKey, ByVal "ProxyServer", 0, REG_SZ, ByVal PS, ByVal LenB(PS))
i = RegSetValueEx(hKey, ByVal "ProxyEnable", 0, REG_DWORD, PEv, LenB(PEv))
i = RegCloseKey(hKey)
Call InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, "", 0)
End Sub
Sub iEsate(IPDRES As String)
Dim ConInfo As INTERNET_PROXY_INFO, lRetValue As Long
ConInfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY
ConInfo.lpszProxy = IPDRES 'IP地址:端口,例如:192.168.1.1:8080
ConInfo.lpszProxyBypass = ""
Call InternetSetOption(0, INTERNET_OPTION_PROXY, ConInfo, LenB(ConInfo))
End Sub
Private Sub Command1_Click()
SetReG 1, "88.23.3.6:80"
End Sub