簡體   English   中英

以編程方式更改Internet Explorer代理(包括密碼)而無需重新啟動,即在vb.net中

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

可能嗎

我知道一種方法是更改​​注冊表。 但是,必須有更好的方法。

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

結束子

這樣做有兩個缺點

  1. 我需要重新啟動Internet Explorer
  2. 我需要通過直接操作Windows來更改代理的用戶名和密碼。

我想要一種更好,更直接的方法。 無論如何?

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