0

I would like to know how do I add proxy username and proxy password to my Form1 to be able change my proxy in windows global settings. For now it is working but only format Proxy IP : Proxy port My proxy provider gave me only proxy

Imports System.IO
Imports System.Net


Public Class Form1


    Private Sub btnconnect_Click(sender As Object, e As EventArgs) Handles btnConnectDisconnect.Click
        Dim clsProxy As New IEProxy
        If My.Settings.IEProxyConnected Then
            If clsProxy.DisableProxy Then
                btnConnectDisconnect.Text = "Connect"
                My.Settings.IEProxyConnected = False
                MessageBox.Show("Proxy successfully disabled.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Error disabling proxy.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
        Else
            If Not (String.IsNullOrEmpty(txtIP.Text) Or String.IsNullOrEmpty(txtPort.Text)) Then
                Dim port As Integer
                Dim proxyIP_user As String = txtUser.Text
                Dim proxyIP_pass As String = txtPass.Text

                If Integer.TryParse(txtPort.Text, port) Then
                    Dim p As WebProxy = New WebProxy(txtIP.Text.Trim, port)

                    Dim credentials As ICredentials = New NetworkCredential(proxyIP_user, proxyIP_pass)
                    My.Settings.RootProxy = p
                    My.Settings.Save()

                    Dim x As WebProxy = New WebProxy(txtIP.Text, True, Nothing, credentials)
                    If clsProxy.SetProxy(p.Address.Host & ":" & p.Address.Port) Then
                        btnConnectDisconnect.Text = "Disconnect"
                        My.Settings.IEProxyConnected = True
                        MessageBox.Show("Proxy successfully enabled.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Else
                        MessageBox.Show("Error enabling proxy.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                End If
            Else
                MessageBox.Show("Please enter the proxy bought from StormProxy.com", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
        End If
        My.Settings.Save()
    End Sub
End Class
Tran
  • 159
  • 1
  • 4
  • 8
  • See whether [this](https://stackoverflow.com/a/51471736/7444103) helps. – Jimi May 06 '20 at 02:50
  • @Jimi I think you not understand. I alreayd have IEProxy.vb class from Microsoft so I dont need the link you sent, It work but if i get user proxy and proxy pass it just doesnt work – Tran May 06 '20 at 03:16
  • Well, I though that looking at what's happening behind the scene, you'd notice that those are just registry settings: User Name and Password of course are not stored there. A Proxy object and its Credentials, if needed, are created along with a new Connection request. Then, you provide new Credentials, with NetworkCredential or CredentialCache (if you need different Credentials for different URIs). Don't save a Proxy object, it's useless, create one when needed. See [WebRequest.GetSystemWebProxy](https://docs.microsoft.com/en-us/dotnet/api/system.net.webrequest.getsystemwebproxy), for example. – Jimi May 06 '20 at 04:06

0 Answers0