如题!!

解决方案 »

  1.   

    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
    Private Const REG_DWORD As Long = 4
    Private Const REG_SZ = 1
    Private Const HKEY_CURRENT_USER = &H80000001
    Private Sub SetSurrogate(address As String, Port As String) '设置代理服务器的地址跟端口
    Dim str As String
    Dim SubKey As String
    Dim hKey As Longstr = Trim(address) & ":" & Trim(Port)
    SubKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
    RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
    RegSetValueEx hKey, "ProxyServer", 0, REG_SZ, ByVal str, LenB(StrConv(str, vbFromUnicode)) + 1
    RegCloseKey hKey
    End SubPrivate Sub SetEnable() 
    Dim SubKey As String
    Dim hKey As LongSubKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
    RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
    RegSetValueEx hKey, "ProxyEnable", 0, REG_DWORD, 1&, 4
    RegCloseKey hKey
    End SubPrivate Sub SetDisable() 
    Dim SubKey As String
    Dim hKey As LongSubKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
    RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
    RegSetValueEx hKey, "ProxyEnable", 0, REG_DWORD, 0&, 4
    RegCloseKey hKey
    End SubPrivate Sub Command1_Click()'使代理服务器可用
    SetSurrogate "192.168.1.199", "200"
    SetEnable
    End SubPrivate Sub Command2_Click()'使代理服务器不可用
    SetDisable
    End Sub