最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

[.NET] Windows系统全局代理IP设置

业界 admin 14浏览 0评论

附C# VB.NET互转工具:https://download.csdn/download/xxxvxxv/10877188

Imports Microsoft.Win32.Registry

Class sysProxy
    ''' <summary>
    ''' 开启代理
    ''' </summary>
    Public Sub open()
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyEnable", &H1)
    End Sub

    ''' <summary>
    ''' 设置代理服务器的地址跟端口
    ''' </summary>
    ''' <param name="str">如127.0.0.1:8888</param>
    Public Sub setproxy(ByVal str As String)
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyServer", str)
        SubKey.SetValue("ProxyEnable", &H1)
    End Sub

    ''' <summary>
    ''' 关闭代理
    ''' </summary>
    Public Sub close()
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyEnable", &H0)
    End Sub

    ''' <summary>
    ''' 代理开关状态
    ''' </summary>
    ''' <param name="proxy"></param>
    ''' <returns></returns>
    Public Function ProxyStatus(ByRef proxy As String) As Boolean
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        proxy = SubKey.GetValue("ProxyServer")
        Return SubKey.GetValue("ProxyEnable")
    End Function
End Class


附C# VB.NET互转工具:https://download.csdn/download/xxxvxxv/10877188

Imports Microsoft.Win32.Registry

Class sysProxy
    ''' <summary>
    ''' 开启代理
    ''' </summary>
    Public Sub open()
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyEnable", &H1)
    End Sub

    ''' <summary>
    ''' 设置代理服务器的地址跟端口
    ''' </summary>
    ''' <param name="str">如127.0.0.1:8888</param>
    Public Sub setproxy(ByVal str As String)
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyServer", str)
        SubKey.SetValue("ProxyEnable", &H1)
    End Sub

    ''' <summary>
    ''' 关闭代理
    ''' </summary>
    Public Sub close()
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyEnable", &H0)
    End Sub

    ''' <summary>
    ''' 代理开关状态
    ''' </summary>
    ''' <param name="proxy"></param>
    ''' <returns></returns>
    Public Function ProxyStatus(ByRef proxy As String) As Boolean
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        proxy = SubKey.GetValue("ProxyServer")
        Return SubKey.GetValue("ProxyEnable")
    End Function
End Class


发布评论

评论列表 (0)

  1. 暂无评论