Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Changing proxy settings without restarting application


Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2005, 04:29 PM
Jason88 Jason88 is offline
Junior Contributor
 
Join Date: Oct 2005
Posts: 301
Default Changing proxy settings without restarting application


Hi, I'm not sure if I should post this in "General", "Communications" or in "File I/O and Registry". I don't know if it's a problem with the proxy, registry or neither, so I hope this is the right place.

I'm changing proxy settings, by saving them in the registry. The proxy is used with a WebBrowser control. The problem is that I need to restart the application before the proxy works. Is there any way around that ?

This is the code I use to change the proxy settings:
Code:
Dim regmod Set regmod = CreateObject("WScript.Shell") 'Set proxy server and port regmod.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", 123.123.123.123:1111, "REG_SZ" 'Enable the proxy server regmod.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
Reply With Quote
  #2  
Old 11-03-2005, 02:35 AM
PlenoJure's Avatar
PlenoJure PlenoJure is offline
'With Full Right'

Retired Moderator
* Guru *
 
Join Date: Jun 2003
Posts: 1,880
Default

Try this:

Code:
Option Explicit Private Type INTERNET_PROXY_INFO dwAccessType As Long lpszProxy As String lpszProxyBypass As String End Type Private Const ERROR_INSUFFICIENT_BUFFER = 122 Private Const INTERNET_OPTION_PROXY = 38 Private Const INTERNET_OPEN_TYPE_DIRECT = 1 Private Const INTERNET_OPEN_TYPE_PROXY As Long = 3 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 Sub cmdProxy_Click() Dim iRet As Long Dim ProxyInfo As INTERNET_PROXY_INFO Dim strProxyInfo As String strProxyInfo = InputBox("Plese enter a proxy.", , "http=127.0.0.1:8080") If strProxyInfo <> "" Then ProxyInfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY Else ProxyInfo.dwAccessType = INTERNET_OPEN_TYPE_DIRECT End If ProxyInfo.lpszProxy = strProxyInfo ProxyInfo.lpszProxyBypass = "<local>" iRet = InternetSetOption(0&, INTERNET_OPTION_PROXY, ProxyInfo, LenB(ProxyInfo)) If iRet <> 0 Then lblStatus.Caption = "Status: Now Using Proxy Service." Else lblStatus.Caption = "Status: Error in Setting IE Proxy Service." End If End Sub
__________________
Adam
-- Please use [vb][/vb] tags for code | Posting Guidelines | Please check the MSDN and Search before posting
-- Other Sites: Did you search Google first? | My Blog
Reply With Quote
  #3  
Old 11-03-2005, 07:26 PM
Jason88 Jason88 is offline
Junior Contributor
 
Join Date: Oct 2005
Posts: 301
Default

Yes, that works. Thank you very much
Reply With Quote
  #4  
Old 11-04-2005, 07:15 PM
Jason88 Jason88 is offline
Junior Contributor
 
Join Date: Oct 2005
Posts: 301
Default

One more question. Is it possible to hide "http=" in the InputBox, so only the IP address and port number have to be typed in ?

To have it shown as "127.0.0.1:8080" in the InputBox instead of "http=127.0.0.1:8080".
Reply With Quote
  #5  
Old 01-16-2007, 06:52 PM
unsosure unsosure is offline
Newcomer
 
Join Date: Jan 2007
Posts: 1
Default

this doesnt seem to work for me.

Dim ProxyInfo As INTERNET_PROXY_INFO

gives me user defined type not defined.

any help?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->