简体   繁体   English

以编程方式更改Internet Explorer代理(包括密码)而无需重新启动,即在vb.net中

[英]Programatically change Internet Explorer Proxy Including the Password Without Restarting ie in vb.net

Is it even possible? 可能吗

I know a way to do so is to change the registry. 我知道一种方法是更改​​注册表。 However there has to be a better way. 但是,必须有更好的方法。

Shared Sub EnableProxy1() 共享子EnableProxy1()

Dim regKey As Microsoft.Win32.RegistryKey

regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
regKey.SetValue("ProxyEnable", True, Microsoft.Win32.RegistryValueKind.DWord)
regKey.SetValue("ProxyServer", proxyhandler.proxyFedtoInternetExplorer, Microsoft.Win32.RegistryValueKind.String)
regKey.SetValue("ProxyOverride", "<local>", Microsoft.Win32.RegistryValueKind.String)
regKey.Close()

End Sub 结束子

Shared Sub DisableProxy() Dim regKey As Microsoft.Win32.RegistryKey 共享子DisableProxy()昏暗regKey作为Microsoft.Win32.RegistryKey

regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)

regKey.SetValue("ProxyEnable", False, Microsoft.Win32.RegistryValueKind.DWord)

regKey.Close()

End Sub 结束子

Doing this has 2 weaknesses 这样做有两个缺点

  1. I need to restart internet explorer 我需要重新启动Internet Explorer
  2. I need to change the username and password of the proxy by manipulating windows directly. 我需要通过直接操作Windows来更改代理的用户名和密码。

I want a method that's better and direct. 我想要一种更好,更直接的方法。 Any ways? 无论如何?

Imports Microsoft.Win32
Public Class ProxySetting
    Public Function IsProxyEnabled() As Boolean
        Try
            Dim Regs As RegistryKey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", RegistryKeyPermissionCheck.ReadWriteSubTree)
            If Regs.GetValue("ProxyEnable") <> Nothing Then
                If Regs.GetValue("ProxyEnable").ToString() = "0" Then
                    Return False
                Else
                    Return True
                End If
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function GetProxyServer() As String
        Try
            Dim Regs As RegistryKey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", RegistryKeyPermissionCheck.ReadWriteSubTree)
            If Regs.GetValue("ProxyServer") <> Nothing Then
                Return Regs.GetValue("ProxyServer").ToString()
            Else
                Return ""
            End If
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Public Sub DisableProxy()
        Dim regKey As RegistryKey
        Try
            regKey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
            regKey.SetValue("ProxyEnable", False, RegistryValueKind.DWord)
            regKey.Close()
        Catch ex As Exception

        End Try
    End Sub

    Public Sub SetProxy(ByVal ServerName As String, ByVal port As Integer)
        Try
            Dim regkey1 As RegistryKey
            regkey1 = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
            regkey1.SetValue("ProxyServer", ServerName + ":" + port.ToString(), RegistryValueKind.Unknown)
            regkey1.SetValue("ProxyEnable", True, RegistryValueKind.DWord)
            regkey1.Close()
        Catch ex As Exception

        End Try
    End Sub

End Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM