added samples
[windows-sources.git] / sdk / samples / Cardspace_samples / TechnologySamples / CardSpace / DecryptingASecurityToken / CS / scripts / Remove-hosts.vbs
blobd366620d8bddae0e0fa3efc9e063ff39581a0d32
1 'use common library
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.
8 on error resume next
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 &")"
16 finished
17 end if
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 &")"
22 finished
23 else
24 log "copied the original hosts ("& hostsfilename &") file to ("& backuphostsfilename &")"
25 end if
29 Set hostsfile = fso.OpenTextFile(backuphostsfilename,ForReading)
30 if err.number <> 0 then
31 logerror "unable to open the hosts file at ("& backuphostsfilename &")"
32 finished
33 end if
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 &")"
38 finished
39 end if
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."
46 else
47 newhostsfile.WriteLine text
48 end if
49 Wend
51 hostsfile.Close
52 newhostsfile.Close
54 REM Remove lines from proxy ignore in the registry.
55 wso.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride", "<local>"
57 finished