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