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

发布于 2024-11-02 19:45:15 字数 1054 浏览 0 评论 0原文

有可能吗?

我知道一种方法是更改​​注册表。然而,必须有更好的方法。

共享子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()

结束子

共享子DisableProxy() Dim regKey As 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

这样做有两个缺点

  1. 我需要重新启动 Internet Explorer
  2. 我需要通过直接操作 Windows 来更改代理的用户名和密码。

我想要一种更好、更直接的方法。有什么办法吗?

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()

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

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
  2. I need to change the username and password of the proxy by manipulating windows directly.

I want a method that's better and direct. Any ways?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如荒岛 2024-11-09 19:45:15
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文