Exit Posted December 22, 2020 Share Posted December 22, 2020 or the short version: ; disable "www.facebook.com" #RequireAdmin $sURL = "www.facebook.com" $sHostsFile = @WindowsDir & "\system32\drivers\etc\hosts" $iReadonly = StringInStr(FileGetAttrib($sHostsFile), "R") If $iReadonly Then FileSetAttrib($sHostsFile, "-R") If Not StringInStr(FileRead($sHostsFile), $sURL) Then FileWrite($sHostsFile, @CRLF & "127.0.0.1" & @TAB & @TAB & $sURL & @CRLF) If $iReadonly Then FileSetAttrib($sHostsFile, "+R") ShellExecute("Notepad.exe", $sHostsFile) PHAK 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
PHAK Posted December 22, 2020 Author Share Posted December 22, 2020 @Exit 1 I did run from a desktop Because you asked for a consul I put in C 2 I did what you brought You are a king 😃👍 The problem seems to have been hosts The file is write-protected. 3 I did not want him to open Notepad So I deleted the lines below ; disable "www.facebook.com" #RequireAdmin $sURL = "www.facebook.com" $sHostsFile = @WindowsDir & "\system32\drivers\etc\hosts" ConsoleWrite(@CRLF & "Admin rights are " & (IsAdmin() ? "" : "NOT ") & "detected." & @CRLF & @CRLF) ConsoleWrite($sHostsFile & " is " & (StringInStr(FileGetAttrib($sHostsFile), "R") ? "readonly." : "writable.") & @CRLF & @CRLF) $sText = FileRead($sHostsFile) ConsoleWrite("Error: " & @error & " Extended: " & @extended & " Line: " & @ScriptLineNumber & @CRLF & @CRLF & $sText & @CRLF & @CRLF) If StringInStr($sText, $sURL) Then ConsoleWrite("URL already present" & @CRLF) Else $iReadonly = StringInStr(FileGetAttrib($sHostsFile), "R") If $iReadonly Then FileSetAttrib($sHostsFile, "-R") ConsoleWrite($sHostsFile & " is " & (StringInStr(FileGetAttrib($sHostsFile), "R") ? "readonly." : "writable.") & @CRLF & @CRLF) $rc = FileWrite($sHostsFile, @CRLF & "127.0.0.1" & @TAB & @TAB & $sURL & @CRLF) ConsoleWrite("Error: " & @error & " Extended: " & @extended & " Line: " & @ScriptLineNumber & " RC: " & $rc & @LF) If $iReadonly Then FileSetAttrib($sHostsFile, "+R") ConsoleWrite($sHostsFile & " is " & (StringInStr(FileGetAttrib($sHostsFile), "R") ? "readonly." : "writable.") & @CRLF & @CRLF) $sText = FileRead($sHostsFile) ConsoleWrite("Error: " & @error & " Extended: " & @extended & " Line: " & @ScriptLineNumber & @CRLF & @CRLF & $sText & @CRLF & @CRLF) EndIf Now there is another problem Going down a row And he put a profit Example 127.0.0.1 prod.adobegenuine.com 127.0.0.1 www.facebook.com There is something to do? It does not bother But if there is a solution I would be happy 😀 Link to comment Share on other sites More sharing options...
GokAy Posted December 23, 2020 Share Posted December 23, 2020 (edited) If I understand you correctly, change this line $rc = FileWrite($sHostsFile, @CRLF & "127.0.0.1" & @TAB & @TAB & $sURL & @CRLF) to include extra CRLF's $rc = FileWrite($sHostsFile, @CRLF & @CRLF & "127.0.0.1" & @TAB & @TAB & $sURL & @CRLF & @CRLF) Edited December 23, 2020 by GokAy PHAK 1 Link to comment Share on other sites More sharing options...
Exit Posted December 23, 2020 Share Posted December 23, 2020 13 hours ago, PHAK said: Now there is another problem Going down a row And he put a profit We have a language barrier here. I can't understand the word profit. Can you describe the problem in your language? I will then translate it into German. PHAK 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Developers Jos Posted December 23, 2020 Developers Share Posted December 23, 2020 26 minutes ago, Exit said: I can't understand the word profit. advance...extra tabs...???? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
PHAK Posted December 23, 2020 Author Share Posted December 23, 2020 @Exit @GokAy I got along I had to remove @CRLF @TAB It's revised ; disable "www.facebook.com" #RequireAdmin $sURL = "www.facebook.com" $sHostsFile = @WindowsDir & "\system32\drivers\etc\hosts" $iReadonly = StringInStr(FileGetAttrib($sHostsFile), "R") If $iReadonly Then FileSetAttrib($sHostsFile, "-R") If Not StringInStr(FileRead($sHostsFile), $sURL) Then FileWrite($sHostsFile, @CRLF & "127.0.0.1" & @TAB & $sURL ) If $iReadonly Then FileSetAttrib($sHostsFile, "+R") Thank you all Link to comment Share on other sites More sharing options...
PHAK Posted December 23, 2020 Author Share Posted December 23, 2020 enable www.facebook.com how do I do it? Link to comment Share on other sites More sharing options...
spudw2k Posted December 24, 2020 Share Posted December 24, 2020 By enable, you mean remove it from the hosts file / undo adding it? You could either get fancy with some regex, or check line by line. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Exit Posted December 24, 2020 Share Posted December 24, 2020 ; enable "www.facebook.com" #RequireAdmin #include <Array.au3> $sURL = "www.facebook.com" $sHostsFile = @WindowsDir & "\system32\drivers\etc\hosts" $iReadonly = StringInStr(FileGetAttrib($sHostsFile), "R") If $iReadonly Then FileSetAttrib($sHostsFile, "-R") $aFile = FileReadToArray($sHostsFile) For $i = @extended - 1 To 0 Step -1 If StringInStr($aFile[$i], $surl) Then _ArrayDelete($aFile, $i) Next FileDelete($sHostsFile) FileWrite($sHostsFile,_ArrayToString($aFile,@CRLF)) If $iReadonly Then FileSetAttrib($sHostsFile, "+R") PHAK 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
PHAK Posted December 24, 2020 Author Share Posted December 24, 2020 2 hours ago, Exit said: ; enable "www.facebook.com" #RequireAdmin #include <Array.au3> $sURL = "www.facebook.com" $sHostsFile = @WindowsDir & "\system32\drivers\etc\hosts" $iReadonly = StringInStr(FileGetAttrib($sHostsFile), "R") If $iReadonly Then FileSetAttrib($sHostsFile, "-R") $aFile = FileReadToArray($sHostsFile) For $i = @extended - 1 To 0 Step -1 If StringInStr($aFile[$i], $surl) Then _ArrayDelete($aFile, $i) Next FileDelete($sHostsFile) FileWrite($sHostsFile,_ArrayToString($aFile,@CRLF)) If $iReadonly Then FileSetAttrib($sHostsFile, "+R") Excellent Amazing This is what I wanted Thank you Champion Exit 1 Link to comment Share on other sites More sharing options...
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