2 ExecuteGlobal
CreateObject("Scripting.FileSystemObject").OpenTextFile( left( WScript
.ScriptFullName
, len (WScript
.ScriptFullName
) -len( WScript
.ScriptName
) ) & "\vb-script-library.vbs",1).ReadAll()
3 InitScript("Hosts file installation")
5 REM GLOBAL SCRIPT OBJECTS
7 REM Set error handler to continue.
9 hostsfilename
= wso
.ExpandEnvironmentStrings("%windir%") & "\System32\drivers\etc\hosts"
10 newhostsfilename
= hostsfilename
& ".new"
11 backuphostsfilename
= hostsfilename
& "."&month(date)&"-"&day(date)&"-"&year(date)&"-" & hour(time
)& minute(time
)&".bak"
13 REM verify the hosts file exists.
14 if not fso
.FileExists(hostsfilename
) then
15 logerror
"unable to locate the hosts file at ("& hostsfilename
&")"
19 fso
.CopyFile hostsfilename
, backuphostsfilename
20 if err
.number
<> 0 or NOT fso
.FileExists(backuphostsfilename
) then
21 logerror
"unable to copy the existing hosts ("& hostsfilename
&") file to ("& backuphostsfilename
&")"
24 log
"copied the original hosts ("& hostsfilename
&") file to ("& backuphostsfilename
&")"
29 Set hostsfile
= fso
.OpenTextFile(backuphostsfilename
,ForReading
)
30 if err
.number
<> 0 then
31 logerror
"unable to open the hosts file at ("& backuphostsfilename
&")"
35 Set newhostsfile
= fso
.OpenTextFile(hostsfilename
,ForWriting
)
36 if err
.number
<> 0 then
37 logerror
"unable to open the new hosts file for writing at ("& hostsfilename
&")"
41 While Not hostsfile
.AtEndOfStream
42 text
= hostsfile
.ReadLine
43 if InStr( 1, text
, "fabrikam" , 1 ) OR InStr( 1, text
, "contoso" , 1 ) OR InStr( 1, text
, "adatum" , 1 )OR InStr( 1, text
, "woodgrovebank" , 1 ) then
44 ' line already exists, drop it.
45 log
"Dropping the line ("& text
&") from the hosts file."
47 newhostsfile
.WriteLine text
54 REM Remove lines from proxy ignore in the registry.
55 wso
.RegWrite
"HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride", "<local>"