返回顶部

收藏

修改代理服务器

更多

VBScript修改代理服务器

changeProxy.vbs

Const HKCU=&H80000001 'HKEY_CURRENT_USER
Const HKLM=&H80000002 'HKEY_LOCAL_MACHINE

Const REG_SZ=1
Const REG_EXPAND_SZ=2
Const REG_BINARY=3
Const REG_DWORD=4
Const REG_MULTI_SZ=7

Const HKCU_IE_PROXY = "Software\Microsoft\Windows\CurrentVersion\Internet
Settings"

Set oReg=GetObject("winmgmts:!root/default:StdRegProv")

Main

Sub Main()

' If Proxy is set then turn it off
If GetValue(HKCU,HKCU_IE_PROXY,"ProxyEnable",REG_DWORD) = 1 AND
Len(GetValue(HKCU,HKCU_IE_PROXY,"ProxyServer",REG_SZ)) > 0 Then
CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",0,REG_DWORD
wscript.echo "Proxy Disabled"
Else
' If Proxy is not set then turn it on

strProxyServer = "MyProxySvr:80"
strProxyOveride = "*.domain.com;*.domain2.com;*domain3.com"

CreateValue HKCU,HKCU_IE_PROXY,"ProxyServer",strProxyServer,REG_SZ
CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",1,REG_DWORD
CreateValue HKCU,HKCU_IE_PROXY,"ProxyOverride",strProxyOveride,REG_SZ
wscript.echo "Proxy Enabled" & vbcrlf & "(" & strProxyServer & ")"
End If

End Sub

Function CreateValue(Key,SubKey,ValueName,Value,KeyType)
Select Case KeyType
Case REG_SZ
CreateValue = oReg.SetStringValue(Key,SubKey,ValueName,Value)
Case REG_EXPAND_SZ
CreateValue =
oReg.SetExpandedStringValue(Key,SubKey,ValueName,Value)
Case REG_BINARY
CreateValue = oReg.SetBinaryValue(Key,SubKey,ValueName,Value)
Case REG_DWORD
CreateValue = oReg.SetDWORDValue(Key,SubKey,ValueName,Value)
Case REG_MULTI_SZ
CreateValue =
oReg.SetMultiStringValue(Key,SubKey,ValueName,Value)
End Select
End Function

Function DeleteValue(Key, SubKey, ValueName)
DeleteValue = oReg.DeleteValue(Key,SubKey,ValueName)
End Function

Function GetValue(Key, SubKey, ValueName, KeyType)

Dim Ret

Select Case KeyType
Case REG_SZ
oReg.GetStringValue Key, SubKey, ValueName, Value
Ret = Value
Case REG_EXPAND_SZ
oReg.GetExpandedStringValue Key, SubKey, ValueName, Value
Ret = Value
Case REG_BINARY
oReg.GetBinaryValue Key, SubKey, ValueName, Value
Ret = Value
Case REG_DWORD
oReg.GetDWORDValue Key, SubKey, ValueName, Value
Ret = Value
Case REG_MULTI_SZ
oReg.GetMultiStringValue Key, SubKey, ValueName, Value
Ret = Value
End Select

GetValue = Ret
End Function

changeproxysettings.vbs

' *  VBScript to change the IE Proxy Server, by directly editing the registry
 ' *  Enjoy!

   Option Explicit

   ' *  Proxy Server

   Dim proxy
   proxy = "172.16.0.1:3128" 'For example at my work it's like that so here you can make some change :)

   ' *  Application Title

   Dim Title
   Title = "Proxy Changer"

   ' *  Welcome Message

   Dim Welcome_Text
   Welcome_Text = "Do you really want to change the Proxy Server to " & proxy & "?"

   Call Welcome()

   Sub Welcome()
       Dim GO
       GO = MsgBox(Welcome_Text, 36, Title)
       If GO = 7 Then
           WScript.Quit
       End If
   End Sub

   ' *  Warning Message

   Dim Warning_Text
   Warning_Text = "Warning:  All current Internet Explorer and Windows Explorer windows will be closed." & Chr(10) _
                   & Chr(10) _
                   & "Do you still wish to continue?"

   Call Warning()

   Sub Warning()
       Dim GO
       GO = MsgBox(Warning_Text, 36, Title)
       If GO = 7 Then
           WScript.Quit
       End If
   End Sub

   ' *  WSHShell

   Dim WSHShell
   Set WSHShell = WScript.CreateObject("WScript.Shell")

   ' *  Kill IE (and consequently WE as well)

   Call Kill_IE()

   Sub Kill_IE()
       While WSHShell.AppActivate("Internet Explorer")
           WSHShell.SendKeys "%{F4}"
           WScript.Sleep 500    ' Impedes a traffic jam
       WEnd
   End Sub

   ' *  Regedits

   WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
   WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", proxy
   WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride", ""
   WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\DisablePasswordCaching", 1, "REG_DWORD"

   ' *  Confirmation

   Dim confirm
   confirm = MsgBox("Proxy Server has been changed to " & proxy & ".  Enjoy.", 64, Title)

   ' *  Open IE

   WSHShell.run "iexplore.exe http://www.google.com"

[ASP/Basic]代码

' Initialize Objects
     Dim LocalClass_StdRegProv: Set LocalClass_StdRegProv = GetObject("winmgmts:{impersonationlevel=impersonate}!//./root/default:StdRegProv")
     Dim EmptyRecordset: Set EmptyRecordset = CreateObject("ADODB.Recordset")
 ' Define Constants
     Const HKEY_CLASSES_ROOT = &H80000000, HKCR = &H80000000
     Const HKEY_CURRENT_USER = &H80000001, HKCU = &H80000001
     Const HKEY_LOCAL_MACHINE = &H80000002, HKLM = &H80000002
     Const HKEY_USERS = &H80000003, HKU = &H80000003
     Const HKEY_PERFORMANCE_DATA = &H80000004, HKPD = &H80000004
     Const HKEY_CURRENT_CONFIG = &H80000005, HKCC = &H80000005
     Const HKEY_DYN_DATA = &H80000006, HKDD = &H80000006
     Const MaxCharacters = 255
     Const adVarChar = 200
     Const adInteger = 3
 ' Dimension Public Variables
     Dim EntryNumber: EntryNumber = 0
     Dim Return

 EmptyRecordset.Fields.Append "Entry", adInteger
 EmptyRecordset.Fields.Append "Name", adVarChar, MaxCharacters
 EmptyRecordset.Fields.Append "Server", adVarChar, MaxCharacters
 EmptyRecordset.Fields.Append "Port", adInteger
 EmptyRecordset.Open

 ' Add server/port
     EntryNumber = EntryNumber + 1
     EmptyRecordset.AddNew
     EmptyRecordset("Entry") = EntryNumber
     EmptyRecordset("Name") = "Entry A"
     EmptyRecordset("Server") = "192.168.0.1"
     EmptyRecordset("Port") = 8080
     EmptyRecordset.Update

     EntryNumber = EntryNumber + 1
     EmptyRecordset.AddNew
     EmptyRecordset("Entry") = EntryNumber
     EmptyRecordset("Name") = "Entry B"
     EmptyRecordset("Server") = "isa1"
     EmptyRecordset("Port") = 8080
     EmptyRecordset.Update

 Dim Message
 EmptyRecordset.MoveFirst
 Do While EmptyRecordset.EOF = False
     Message = Message & EmptyRecordset("Entry").Value & "." & vbTab & EmptyRecordset("Name").Value & vbCrLf
     EmptyRecordset.MoveNext
 Loop

 Do
     Dim intAnswer: intAnswer = InputBox(Message, "Choose an entry", "1")
     If IsNumeric(intAnswer) = True Then intAnswer = CLng(intAnswer)
     If intAnswer > EmptyRecordset.RecordCount Or intAnswer < 0 Then WScript.Echo "Invalid entry, please try again..."
 Loop Until (((VarType(intAnswer) And vbLong) = vbLong) And intAnswer <= EmptyRecordset.RecordCount And intAnswer >= 0)

 Select Case True
     Case (intAnswer = 0)
         WScript.Echo "Cancelled. Exiting."
     Case (((VarType(intAnswer) And vbLong) = vbLong) And intAnswer <= EmptyRecordset.RecordCount And intAnswer > 0)
         EmptyRecordset.Filter = "Entry=" & intAnswer
         Dim ProxyServer: ProxyServer = EmptyRecordset("Server").Value & ":" & EmptyRecordset("Port").Value
         intAnswer = MsgBox("Would you like to set the proxy to " & EmptyRecordset("Name").Value & " (" & ProxyServer & ")?", vbQuestion + vbYesNo + vbSystemModal, "Confirm")
         If intAnswer = vbYes Then
             Return = LocalClass_StdRegProv.SetDWORDValue(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 1)
             Return = LocalClass_StdRegProv.SetStringValue(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", ProxyServer)
             If Err.Number = 0 And Return = 0 Then
                 WScript.Echo "Proxy settings changed. Exiting."
             Else
                 WScript.Echo "Proxy settings not changed. Exiting."
             End If
         Else
             WScript.Echo "No changes made. Exiting."
         End If
     Case Else
         WScript.Echo "Invalid entry. Exiting"
 End Select

标签:ASP.NET/Basic

收藏

0人收藏

支持

0

反对

0

发表评论