In the document "setting the COOKIE and Temporary Folder paths of WebBrowser in VB", we introduced how to set the cookie Path for Webbrowser. Likewise, we can set a proxy for Webbrowser. However, if the program does not have the Webbrowser control and other network functions are used, how can I set a proxy? We can call the InternetSetOption function in wininet. dll. Okay. The core code is provided directly.
'================================================ =
'Declaring function: Set a proxy for this instance
'================================================ =
Private Const INTERNET_OPTION_PROXY = 38
Private Const URLMON_OPTION_USERAGENT = & hsf-001
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const INTERNET_OPTION_SETTINGS_CHANGED = 39
Private Declare Sub UrlMkSetSessionOption Lib "urlmon. dll" (ByVal dwOption As Long, pbuffer As Any, ByVal dwBufferLength As Long, ByVal dwreserved As Long)
Private Type INTERNET_PROXY_INFO
DwAccessType As Long
LpszProxy As String
LpszProxyBypass As String
End Type
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
'================================================ =
'Function name: SetProxy
'Function: sets a proxy for this instance.
'Function parameters: for example, SOCKS = 127.0.0.1: 1987
'================================================ =
Public Function SetProxy (ByVal Proxy As String)
Dim options As INTERNET_PROXY_INFO
Options. dwAccessType = INTERNET_OPEN_TYPE_PROXY
Options. lpszProxy = Proxy
Options. lpszproxybypass = ""
Internetsetoption 0, internet_option_proxy, options, lenb (options)
Internetsetoption internet_option_settings_changed, 0, 0, 0
End Function