特色奶茶店加盟排行榜:使用VB设置IE代理

来源:百度文库 编辑:偶看新闻 时间:2024/04/29 12:24:56

'硬盘差点坏掉,赶紧把以前收集的代码存起来.....

Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
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 Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
    ByVal lpReserved As Long, lpType As Long, lpData As Any, _
    lpcbData As Long) As Long

   
Private Sub SetSurrogate(address As String, Port As String)                 '设置代理服务器的地址跟端口
    Dim str     As String
    Dim SubKey     As String
    Dim hKey     As Long
    str = 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 Sub
   
Private Sub SetEnable()
    Dim SubKey     As String
    Dim hKey     As Long
    SubKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
    RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
    RegSetValueEx hKey, "ProxyEnable", 0, REG_DWORD, 1&, 4
    RegCloseKey hKey
End Sub
   
Private Sub SetDisable()
    Dim SubKey     As String
    Dim hKey     As Long
    SubKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
    RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
    RegSetValueEx hKey, "ProxyEnable", 0, REG_DWORD, 0&, 4
    RegCloseKey hKey
End Sub

Private Sub Command1_Click()    '使代理服务器可用
    If Check1.Value = 1 Then
        SetSurrogate Text1, Text2
        SetEnable
    Else
        SetDisable
    End If
    ShowProxy
End Sub

Private Sub Command2_Click()
    ShowProxy
End Sub

Sub ShowProxy()
    Dim hKey As Long, ret As Long, lenData As Long, typeData As Long
    Dim sValue As String, s()     As String
    ret = RegOpenKey(&H80000001, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", hKey)
    ret = RegQueryValueExString(hKey, "ProxyServer", 0&, typeData, 0&, lenData)
    sValue = String(lenData, 0)
    ret = RegQueryValueExString(hKey, "ProxyServer", 0&, typeData, sValue, lenData)
    If Len(sValue) > 1 Then
        vValue = Left$(sValue, lenData - 1)
        s = Split(vValue, ":")
        Text1 = s(0)
        Text = s(1)
    Else
        Text1 = ""
        Text2 = ""
    End If
   
    ret = RegQueryValueExString(hKey, "ProxyEnable", 0&, typeData, 0&, lenData)
    sValue = String(lenData, 0)
    ret = RegQueryValueExString(hKey, "ProxyEnable", 0&, typeData, sValue, lenData)
    If Len(sValue) > 1 Then
        vValue = Left$(sValue, lenData - 1)
        If vValue = 1 Then Check1.Value = 1
    End If
   
   
    RegCloseKey hKey
   
End Sub


Private Sub Form_Load()
    ShowProxy
End Sub