Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Block a site via the file Hosts

Status
Not open for further replies.

hackoo

Programmer
Jan 31, 2003
28
TN
Hi to everybody !
I explain a little the purpose of this script: it's how to Block a site. So I found A simple solution which consists in using the file hosts of Windows.
This file is in c:\windows\system32\drivers\etc (Windows XP) or c:\winnt\system32\drivers\etc (Windows NT4, 2000) or c:\Windows (Windows 95, 98 Mrs) Example "to block" In the file HOSTS at the end you add 127.0.0.1 Now that this script works very well I wish to make the other one but with the aim of Unblocking this site which I already have previously Block it.
So I have to read the file hosts line by line and if I find the blocked site I delete it either to replace it by a white or spaces out.
Here i added the code source to block a site.
Now i wonder how to make unblock.vbs
Thank you in advance!!!
Code:
dim Fso,f
Dim rep,label,titre,defaut,data
label="Enter the field below The site that you want to Block for Example [URL unfurl="true"]www.pagedepubs.com[/URL] "
defaut=""
titre="Bloquer les Sites Interdits"
rep=InputBox(label,titre,defaut)
Set Fso = CreateObject("Scripting.FileSystemObject")
sys32=Fso.GetSpecialFolder(1)
Set f = fso.OpenTextFile(sys32+"\DRIVERS\ETC\hosts", 8)
if rep="" then Cleanup
f.Write vbnewline
f.Write "127.0.0.1   "  &rep
 
Sub Cleanup()
  Set FSO = Nothing
  WScript.Quit
End Sub
 
you will need to read the contents of the existing file then write out a new file. what i mean is that you cant update the middle of an existing file, the writeline methods are really just for adding to the end of an existing file.

so,
+ read the existing file into memory (Array, hashtable, one big string etc)
+ manipulate the stuff you have in memory
+ write the file out again, over the top of the existing one

(take a backup of the file you are going to overwrite etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top