Syncronicity in action! I just made this last week. I'll get back after
checking it out.
Code:
;;; Hosts-file Utility v0.2 bLisTeRinG 2004
;Run, properties c:\autoexec.bat
#Persistent
#SingleInstance
;;; Locate an ini-file -check the Command-line.
in = %A_ScriptDir%\HostUtil.ini
If %0% <> 0
{
iPath = %1%
}
Else
{
iniRead, iPath, %in%, options, iniPath
}
If iPath = ERROR
iPath = %in%
IfNotExist, %iPath%
GoSub, hoIniSet
;;; Locate the Hosts-file.
iniRead, ho, %iPath%, options, HostsFile
oh = %ho%.off
IfNotExist, %ho%
IfNotExist, %oh%
{
ho = C:\Windows\Hosts
oh = %ho%.off
IfNotExist, %ho%
IfNotExist, %oh%
{
ho = C:\Windows\System32\Etc\Hosts
oh = %ho%.off
IfNotExist, %ho%
IfNotExist, %oh%
GoSub, hoHoSet
}
}
;;; Locate an Editor.
iniRead, ed, %iPath%, options, Editor
IfNotExist, %ed%
{
ed = C:\Progra~1\Tools\ePad\EditPad.exe
IfNotExist, %ed%
GoSub, hoEdSet
}
;;; Check status of Hosts-file & Setup Tray-Menu.
Menu, tray, add, &Active, hoToggle
IfExist %ho%
{
tg = 1
Menu, tray, Check, &Active
}
Else
{
tg = 0
Menu, tray, UnCheck, &Active
IfNotExist %oh%
GoSub hoHoSet
}
Menu, tray, Default, &Active
Menu, tray, add, &Edit, hoEdit
Menu, tray, add, &Paste, hoPaste
Menu, tray, add ;separator
Menu, tray, add, &Setup, hoSet
Menu, tray, add, &Help, hoHelp
Menu, tray, add, E&xit, hoExit
Menu, tray, NoStandard
Return
;;; All the routines in alphabetical order.
hoChk:
IfExist %ho%
{
tg = 1
Menu, tray, Check, &Active
}
Else
{
tg = 0
Menu, tray, UnCheck, &Active
}
Return
hoEdit:
GoSub hoChk
If tg = 1
{
Run, %ed% %ho%
}
Else
{
Run, %ed% %oh%
}
Return
hoEdSet:
FileSelectFile, hoho, 8, *.exe, Choose Editor (%ed%)
If ErrorLevel = 1, Return
MsgBox, 4100, Choose Editor, `nOld Editor:`n%ed%`n`nNew Editor:`n%hoho%, 8
IfMsgBox, No
{
Return
}
iniWrite, %hoho%, %iPath%, options, Editor
ed = %hoho%
hoho =
Return
hoExit:
ed =
ho =
hoho =
in =
iPath =
oh =
tg =
Exit
hoHelp:
GoSub hoChk
If tg = 1
{
hoho = %ho%
}
Else
{
hoho = %oh%
}
MsgBox, `nActive:`tToggles the Filtering On/Off.`nEdit:`tEdit the Hosts-file.`nPaste:`tNew server address(es)`n`t...to Hosts-file filter.`n`nHosts:`t%hoho%`n`nEditor:`t%ed%`n`nini-file:`t%iPath%`n
Return
hoHoSet:
FileSelectFile, hoho, 8, C:\Windows\ hosts*, Choose Hosts File (%ho%)
If ErrorLevel = 1, Return
MsgBox, 4100, Choose Hosts File, `nOld Hosts File:`n%ho%`n`nNew Hosts File:`n%hoho%, 8
IfMsgBox, No
{
If ed =
Return
hoho = 1
Return
}
iniWrite, %hoho%, %iPath%, options, HostsFile
ho = %hoho%
oh = %ho%.off
hoho =
Return
hoIniSet:
FileSelectFile, hoho, 8, %A_ScriptDir%\ *.ini, Choose Initialization File (%iPath%)
If ErrorLevel = 1, Return
MsgBox, 4100, Choose Initialization File, `nOld iniFile:`n%iPath%`n`nNew iniFile:`n%hoho%,
IfMsgBox, No
{
If ed =
Return
hoho = 1
Return
}
iniWrite, %hoho%, %in%, options, iniPath
iniWrite, %hoho%, %hoho%, options, iniPath
If ed <> 0
{
Reload
Sleep, 1000
}
iPath = %hoho%
hoho =
Return
hoPaste:
GoSub hoChk
Inputbox, hoho, Clipboard, Entries should look something like this:`n www.greedypigs.com,,280,140,,,,,%clipboard%
If ErrorLevel = 1
{
Return
}
If tg = 1
{
FileAppend, `n0 %hoho%, %ho%
}
Else
{
FileAppend, `n0 %hoho%, %oh%
}
Return
hoSet:
GoSub hoIniSet
If hoho = 1, Return
hoho =
GoSub hoHoSet
If hoho = 1, Return
hoho =
GoSub hoEdSet
hoho =
Return
hoToggle:
GoSub hoChk
If tg = 1
{
FileMove, %ho%, %oh%
tg = 0
Menu, tray, UnCheck, &Active
}
Else
{
FileMove, %oh%, %ho%
tg = 1
Menu, tray, Check, &Active
}
Suspend
Return