Link to home
Start Free TrialLog in
Avatar of fab1970
fab1970

asked on

How to get Proxy settings from the default browser, and use them

I'm building a telnet application, and i want to support proxy.
The question is: How to get the proxy settings from the default browser?
(i say "default browser" 'cause i always use IE, i don't know if others have differents way to use a proxy)

Avatar of sj_hicks
sj_hicks
Flag of Australia image

IE proxy settings live in the registry:  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
Put following in a module
*-----------------

Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegOpenKeyA Lib "advapi32.dll" (ByVal hKey As Long, ByVal SubKey As String, Result As Long) As Long
Public Declare Function RegQueryValueExA Lib "advapi32.dll" (ByVal hKey As Long, ByVal KVName As String, ByVal Rvd As Long, Tpe As Long, Dta As Any, cbDta As Long) As Long

Public Function ReadRegistry(hKey As Long, KeyPath As String, SValue As String, Optional Default As String) As String
On Error Resume Next
Dim Buffr As String
RegOpenKeyA hKey, KeyPath, hCurKey
RegQueryValueExA hCurKey, SValue, 0&, lngValueType, ByVal 0&, lngDataBufferSize
Buffr = String(lngDataBufferSize, " ")
RegQueryValueExA hCurKey, SValue, 0&, 0&, ByVal Buffr, lngDataBufferSize
ZPos = InStr(Buffr, Chr$(0))
ReadRegistry = Left$(Buffr, ZPos - 1)
RegCloseKey hCurKey 'close Key !!
End Function
*-----------------

Then a textbox and put following in form load event

*------------------------
Text1.Text = ReadRegistry(&H80000001, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer")
*------------------------

I think this will solver your purpose.

Ashish

Avatar of fab1970
fab1970

ASKER

mmmhh
I think i've encountered a version problem:
i'm actually working on a Win98SE machine, i've found that in
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
i have a subkey called "Connections" containing two Binary value, "DefaultConnectionSettings" and "SavedLegacySettings".
Have each Windows version a different place to store these data?
More: how to "extract" settings from these values?
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial