Does anyone know how to set up proxy setting when using the winsock control? I have an ftp program and I want to give them the option to set this if needed.
thanks
Printable View
Does anyone know how to set up proxy setting when using the winsock control? I have an ftp program and I want to give them the option to set this if needed.
thanks
That's the way you would go about setting a user specified proxy.Code:Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ = 1
Private Const REG_BINARY = 3
Private Const REG_DWORD = 4
Private Const ERROR_SUCCESS = 0&
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
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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 RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Public Sub savestring(Hkey As Long, strPath As String, strValue As String, strdata As String)
On Error Resume Next
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End Sub
'To enable the proxy
Call savestring(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 1)
'to set the proxy to whatever the user specifies
'Text1 is the proxy ip and texy2 is the port
Dim proxy As String
proxy = Text1.Text & ":" & Text2.TExt
'Set the proxy
Call savestring(HKEY_CURRENT_USER, "\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", proxy)
'Do the rest of your code here.
Gl,
D!m