Roberto Alves

Scripting and server based computing

.VBS to automatic configuration of proxy servers at Internet Explorer

Script to be used on notebooks, when a user uses a notebook inside of your company with a proxy server and at another networks without proxy servers, like home. The script execute a ping to a server (that can be the proxy server), if the ping command is successfully then Internet Explorer will be open configured to use a proxy server. If ping command fails, then Internet Explorer will be open without a proxy server.
Create a shortcut with the Internet Explorer icon with the follow address:
%windir%system32wscript.exe “c:program filesinternet explorerabrir_ie.vbs”

After, create a vbs script denominated abrir_ie.vbs, inside of Internet Explorer folder and put the code:
(Don’t forget of change strHost value to one of yours servers)

Option Explicit
Dim strHost,oreg
strHost = “172.20.200.3″
set oreg = CreateObject(“WScript.Shell”)
if Ping(strHost) = True then
‘Wscript.Echo “Host ” & strHost & ” contacted”
oreg.RegWrite “HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet SettingsAutoConfigURL”,”http://172.20.200.32:801/array.script”, “REG_SZ”
oreg.run “iexplore http://www.google.com.br”
Else
‘Wscript.Echo “Host ” & strHost & ” could not be contacted”
set oreg = CreateObject(“WScript.Shell”)
oreg.RegWrite “HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet SettingsAutoConfigURL”,”", “REG_SZ”
oreg.run “iexplore about:blank”
end if
Function Ping(strHost)
dim objPing, objRetStatus
set objPing = GetObject(“winmgmts:{impersonationLevel=impersonate}”).ExecQuery _
(“select * from Win32_PingStatus where address = ‘” & strHost & “‘”)
for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
‘WScript.Echo “Status code is ” & objRetStatus.StatusCode
else
Ping = True
‘Wscript.Echo “Bytes = ” & vbTab & objRetStatus.BufferSize
‘Wscript.Echo “Time (ms) = ” & vbTab & objRetStatus.ResponseTime
‘Wscript.Echo “TTL (s) = ” & vbTab & objRetStatus.ResponseTimeToLive
end if
next
End Function

Category: Scripts

Your email address will not be published. Required fields are marked *

*