1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
| '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Script to change Internet Explorer's Proxy settings
'
' commandline usage:
'
' IEProxy.vbs [<proxy server>[:<proxy port>]] [/o <proxy override parameters]
'
' examples:
'
' IEProxy 10.11.12.13
' IEProxy squid.provider.net:8080
' IEProxy proxysrv /o 10.*; 172.16.*; 192.168.*
' IEProxy /o *.local
' IEProxy disable
'
' (c) 2003 Brahiewahiewa
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
Set WshShell = WScript.CreateObject( "WScript.Shell" ) 'Create the Shell object
Set objArgs = WScript.Arguments 'Read the commandline arguments
If objArgs.Count > 0 Then
bSilent = True 'Don't throw input- or message boxes
If UCASE ( objArgs ( 0 ) ) = "/O" Then 'No new proxy server entered, only overrides
strNewProxy = ""
Else
strNewProxy = objArgs ( 0 )
End If
For i = 0 To objArgs.count - 1
If UCASE ( objArgs ( i ) ) = "/O" Then
strOverride = ""
For j = i + 1 To objArgs.count -1
strOverride = strOverride & objArgs ( j ) 'Put all remaining args into 1 string
Next 'j
End If
Next 'i
End If
intProxyEnabled = ReadProxyReg ( "ProxyEnable" ) 'Read the registry to determine whether or not the proxy server is enabled
If intProxyEnabled > 0 Then
strProxy = ReadProxyReg ( "ProxyServer" )
strProxyServer = Left (strProxy, InStr ( strProxy, ":" ) - 1 ) 'split server and port at the colon
strProxyPort = Right (strProxy, Len ( strProxy ) - InStr ( strProxy, ":" ) )
End If
If Not bSilent Then 'No commandline args; throw InputBox
If intProxyEnabled = 1 Then
strCurProxyMsg = "Current Proxy settings are: " & strProxyServer & ":" & strProxyPort
Else
strCurProxyMsg = "Currently a proxy server is disabled."
End If
strNewProxy = InputBox ( strCurProxyMsg & VbCrLf & VbCrLf &_
"Enter a New proxy : port combination or leave blank for no change" &_
VbCrLf & "enter 'disable' to clear the proxy settings" )
End If
If Not strNewProxy = "" Then 'No text entered in the inputbox
If InStr ( strNewProxy, ":" ) = 0 Then 'Check whether or not the port is specified; default to 80
strNewProxyServer = strNewProxy
strNewProxyPort = "80"
Else 'split the string at the colon
strNewProxyServer = Left (strNewProxy, InStr ( strNewProxy, ":" ) - 1 )
strNewProxyPort = Right (strNewProxy, Len ( strNewProxy ) - InStr ( strNewProxy, ":" ) )
End If
If UCASE ( strNewProxyServer ) = "DISABLE" Then
If Not bSilent Then
MsgBox "Proxy Server will be disabled", VbOkOnly
Else
WScript.Echo "Proxy Server will be disabled"
End If
iRes = WriteProxyReg ( "ProxyServer", "", "REG_SZ" ) 'Also clear the other reg values
iRes = WriteProxyReg ( "ProxyOverride", "", "REG_SZ" )
iRes = WriteProxyReg ( "ProxyEnable", 0, "REG_DWORD" )
WScript.Quit ( iRes )
End If
iRes = WriteProxyReg ( "ProxyServer", Trim ( strNewProxyserver ) & ":" & Trim ( strNewProxyPort ) , "REG_SZ" )
iRes = WriteProxyReg ( "ProxyEnable", 1, "REG_DWORD" )
End If
strOldOverride = ReadProxyReg ( "ProxyOverride" )
If Not bSilent Then
strOverride = InputBox ( "Current Override settings are: " & strOldOverride & VbCrLf &_
"Please enter new string or cancel for no changes," & VbCrLf &_
"enter 'disable' to clear override settings" )
End If
If Not strOverride = "" Then
If UCASE ( strOverride ) = "DISABLE" Then
iRes = WriteProxyReg ( "ProxyOverride", "", "REG_SZ" )
Else
iRes = WriteProxyReg ( "ProxyOverride", strOverride, "REG_SZ" )
End If
End If
If strProxyServer = "" Then
strProxyServer = "<none>"
strProxyPort = "<none>"
End If
strResult = "Old proxy server: " & strProxyServer & VbCrLf
strResult = strResult & "Old proxy port: " & strProxyPort & VbCrLf
If strOldOverride = "" Then strOldOverride = "<none>"
strResult = strResult & "Old overrides: " & strOldOverride & VbCrLf & VbCrLf
If strNewProxyServer = "" Then
strResult = strResult & "New Proxy server: " & strProxyServer & VbCrLf
strResult = strResult & "New Proxy port: " & strProxyPort & VbCrLf
Else
If UCase ( strNewProxyServer ) = "DISABLE" Then
strNewproxyServer = "<none>"
strNewproxyPort = "<none>"
End If
strResult = strResult & "New Proxy server: " & strNewproxyServer & VbCrLf
strResult = strResult & "New Proxy port: " & strNewproxyPort & VbCrLf
End If
If strOverride = "" Then
strResult = strResult & "New Overrides: " & strOldOverride
Else
If UCase ( strOverride ) = "DISABLE" Then strOverride = "<none>"
strResult = strResult & "New Overrides: " & strOverride
End If
If Not bSilent Then
MsgBox strResult, VbOkOnly, "REPORT"
Else
WScript.Echo strResult
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function WriteProxyReg ( strKey, strValue, strType )
strKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\" & strKey
Err.Clear
WshShell.RegWrite strKey, strValue, strType
If Err.Number <> 0 Then WScript.Quit ( Err.Number )
WriteProxyReg = Err.Number
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function ReadProxyReg ( strKey )
strKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\" & strKey
Err.Clear
ReadProxyReg = WshShell.RegRead ( strKey )
If Err.Number <> 0 Then WScript.Quit ( Err.Number )
End Function |