The "Delete" button will remove the selected domain name from the block list.
The "Delete All" button will delete the hosts file and create a new empty one i.e. no websites are blocked.
The "Restore" button will restore the hosts file back to before you started editing it. (a backup of the hosts file is created when the script starts).
;Checks if HOSTS file exists If A_OSVersion = WIN_XP { ;XP Home Ifexist, C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS hostsdir=C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS ;XP Pro ifexist, c:\winnt\system32\drivers\etc\hosts hostsdir= c:\winnt\system32\drivers\etc\hosts } If A_OSVersion in WIN_2000, WIN_NT4 { Ifexist, C:\WINNT\SYSTEM32\DRIVERS\ETC\HOSTS hostsdir=C:\WINNT\SYSTEM32\DRIVERS\ETC\HOSTS } If A_OSVersion in WIN_95, WIN_98, WIN_ME { Ifexist, c:\windows\HOSTS hostsdir= c:\windows\HOSTS } if hostsdir= { msgbox, Hosts file not found or OS not supported exitapp } ; backup hosts file before editing filedelete, %hostsdir%.bak FileCopy, %hostsdir%, %hostsdir%.bak site= Loop, read, %hostsdir% { Loop, parse, A_LoopReadLine, `n { if A_LoopField <> ifnotinstring, A_LoopField, # ifnotinstring, A_LoopField, localhost site=%A_LoopField%|%site% } } stringreplace, site, site, 127.0.0.1,,all stringreplace, site, site, %a_space%,,all Gui, Add, Text,x26 y5 w100 h20,Enter Site to Block: Gui, Add, Edit, vBlocksite x26 y20 w320 h20, website.com Gui, Add, Button, gBlock x356 y20 w60 h20, Block Gui, Add, ListBox, x16 y50 w410 h190 AltSubmit sort,%site% Gui, Add, Button, x16 y250 w60 h20 gDelete, Delete Gui, Add, Button, x76 y250 w60 h20 gRemove_all, Delete all Gui, Add, Button, x136 y250 w60 h20 gRestore, Restore Gui, Show, x404 y320 h285 w442, Hosts Editor Return Delete: ControlGet, todelete, Choice, , ListBox1, Hosts Editor Loop, read, %hostsdir% { line=%A_LoopReadLine% IfInString, line, %todelete% StringReplace, line, line,%line%,,All file=%file%`n%line% } filedelete, %hostsdir% fileappend, %file% ,%hostsdir% GuiControlGet, Number, , ListBox1 control, Delete, %Number%, ListBox1, Hosts Editor return Block: ControlGetText, Blocksite, Edit1, Hosts Editor if Blocksite= msgbox, No website was entered., return stringreplace, Blocksite, Blocksite, http://, StringRight, Slash, Blocksite, 1 if Slash=/ StringTrimRight, Blocksite, Blocksite, 1 fileappend, `n127.0.0.1 %Blocksite%, %hostsdir% control, Add, %Blocksite%, ListBox1, Hosts Editor msgbox, %Blocksite% has been Blocked return Restore: filedelete, %hostsdir% Loop, read, %hostsdir%.bak, %hostsdir% { FileAppend, %A_LoopReadLine%`n siterestore=%A_LoopField%|%site% } GuiControl,, ListBox1, %siterestore% msgbox, All changes since last edit have been removed. return Remove_all: filedelete, %hostsdir% fileappend,127.0.0.1 localhost`n,%hostsdir% GuiControl,, ListBox1, | msgbox, All Sites have been unblocked return GuiClose: ExitApp