Obtain the "Proxy Server" configuration of IE Through VB + API

Source: Internet
Author: User

Option explicit
Private type internet_proxy_info
Dwaccesstype as long
Lpszproxy as long
Lpszproxybypass as long
End type
Private const internet_option_proxy = 38
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 internetqueryoption lib "wininet. dll" alias "internetqueryoptiona" (byval hinternet as long, byval dwoption as long, byref lpbuffer as any, byref dwbufferlength as long) as long
Private declare sub copymemory lib "Kernel32" alias "rtlmovememory" (byref pdest as any, byref psource as any, byval length as long)
Private declare function lstrcpy lib "Kernel32" alias "lstrcpya" (byval lpstring1 as string, byval lpstring2 as long) as long
Private declare function lstrlen lib "Kernel32" alias "lstrlena" (byval lpstring as any) as long
Public Function getproxyaddressandport (optional proxytype as string) as string
Dim proxyinfo as internet_proxy_info
Dim arrbuffer () as byte
Dim straddress as string
Dim strbypass as string
Redim arrbuffer (0-4095)
Internetqueryoption 0 &, internet_option_proxy, arrbuffer (0), ubound (arrbuffer)-lbound (arrbuffer) + 1
Copymemory proxyinfo, arrbuffer (0), lenb (proxyinfo)
Straddress = VBA. Space (lstrlen (proxyinfo. lpszproxy ))
Lstrcpy byval straddress, proxyinfo. lpszproxy
'Do not use the proxy address strbypass
Strbypass = VBA. Space (lstrlen (proxyinfo. lpszproxybypass ))
Lstrcpy byval strbypass, proxyinfo. lpszproxybypass
'Getproxyaddressandport = VBA. trim (VBA. replace (straddress, "", ";") '& ";" & VBA. replace (strbypass ,"",";"))
Getproxyaddressandport = VBA. Trim (VBA. Replace (straddress, "", ";") & ";" & VBA. Replace (strbypass ,"",";"))
Dim proxyarray () as string
Proxyarray = Split (getproxyaddressandport ,";")
Dim I as integer
For I = lbound (proxyarray) to ubound (proxyarray)
If proxyarray (I) like "*" & proxytype & "= *" then
Getproxyaddressandport = VBA. Replace (proxyarray (I), proxytype & "= ","")
Exit
End if
Next I
End Function

Private sub commandementclick ()
Msgbox getproxyaddressandport ("HTTP ")
Msgbox getproxyaddressandport ("ftp ")
Msgbox getproxyaddressandport ("Gopher ")
End sub

'Internetsetoption is required for the "Proxy Server" for IE programming configuration.
'Download an example:
'Http: // www.vbip.com/forum/files/webbrowser_proxy.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.