copyleft Posted March 29, 2019 Posted March 29, 2019 (edited) Does Autoit not recognize C:\Windows\System32\drivers\etc\hosts as a file and not a directory, or is there some other error going on in my script? I'm trying to toggle the Windows host file on and off by renaming it on the fly. Also, is it possible to create some kind of persistent visual flag to indicate the host file is on or off, that shuts off when the browser window is closed? #include <File.au3> #include <MsgBoxConstants.au3> $sFile = @SystemDir & "\drivers\etc\host" If FileExists($sFile) Then MsgBox(4160, "Host", "Host file disabled", 3) Filemove (@SystemDir & "\drivers\etc\host", @SystemDir & "\drivers\etc\host_old", $FC_OVERWRITE) Else FileMove(@SystemDir & "\drivers\etc\host_old", @SystemDir & "\drivers\etc\host", $FC_OVERWRITE) EndIf Edited March 29, 2019 by copyleft
abberration Posted March 29, 2019 Posted March 29, 2019 I think it recognizes it properly. I tried this code to get the file size: $i = FileGetSize(@SystemDir & "\drivers\etc\hosts") MsgBox(0, "", $i) And it returned the right file size. It may be because you have it as host when it should be hosts. Another possible problem is Windows locking on to the file. Try compiling the code, right-click on the executable and go to Run As Administrator. Easy MP3 | Software Installer | Password Manager
copyleft Posted March 29, 2019 Author Posted March 29, 2019 @abberrationabberration. Thanks for the spelling catch. That fixed it. If anyone else has ideas for a persistent browser flag, rather than a message box. I'm all ears.
abberration Posted March 29, 2019 Posted March 29, 2019 You could create a borderless gui or use a tray tip. Easy MP3 | Software Installer | Password Manager
copyleft Posted March 29, 2019 Author Posted March 29, 2019 @abberration Yeah, I finally compromised on using the tray tip. It's not persistent and doesn't close with the browser. But it serves the purpose of alerting users. Thanks very much for your help abberration. #include <File.au3> #include <MsgBoxConstants.au3> #include <TrayConstants.au3> $sFile = @SystemDir & "\drivers\etc\hosts" If FileExists($sFile) Then TrayTip("Hosts", "Host file is not active", 30, $TIP_ICONASTERISK) MsgBox($MB_SYSTEMMODAL, "", "Click to deactivate host file") ; TrayTip("clears any tray tip", "", 0) Filemove (@SystemDir & "\drivers\etc\hosts", @SystemDir & "\drivers\etc\hosts_old", $FC_OVERWRITE) Else FileMove(@SystemDir & "\drivers\etc\hosts_old", @SystemDir & "\drivers\etc\hosts", $FC_OVERWRITE) EndIf
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now