JRZJulien Posted June 29, 2015 Share Posted June 29, 2015 Dears,i want add one recorder into HOSTS file file with following script in windows 7, but always failed, does anyone help me to correct it ?--script start--Local $sUserName = "Administrator"Local $sPassword = "abcd1234"RunAs($sUserName,@computername,$sPassword,0,"attrib -s -h -r C:\Windows\System32\drivers\etc\hosts")RunAs($sUserName,@computername,$sPassword,0,"echo xxx.xxx.xxx.xxx www.google.com" & @CRLF)RunAs($sUserName,@computername,$sPassword,0,"attrib +s +h +r C:\Windows\System32\drivers\etc\hosts")--script end-- Link to comment Share on other sites More sharing options...
Shane0000 Posted June 29, 2015 Share Posted June 29, 2015 (edited) This works for me:Local $sUserName = "xxxx" Local $sPassword = "xxxx" Local $sHostFile = "C:\Windows\System32\drivers\etc\hosts" RunAs($sUserName,@computername,$sPassword,0,"attrib -s -h -r " & $sHostFile) ;RunAs($sUserName,@computername,$sPassword,0,"echo xxx.xxx.xxx.xxx www.google.com" & @CRLF) $hFile = FileOpen($sHostFile, $FO_APPEND) FileWrite($hFile,"echo xxx.xxx.xxx.xxx www.google.com" & @CRLF) FileClose($hFile) Run("Notepad.exe " & $sHostFile) RunAs($sUserName,@computername,$sPassword,0,"attrib +s +h +r " & $sHostFile) Edited June 29, 2015 by Shane0000 Link to comment Share on other sites More sharing options...
JRZJulien Posted June 29, 2015 Author Share Posted June 29, 2015 (edited) Hi Shane0000, from your code, i got the error message:$FO_APPEND Error: Variable used without being declared.i try another command like below:Local $sUserName = "aaaaa" Local $sPassword = "bbbbb" RunAs($sUserName,@computername,$sPassword,0,"attrib -s -h -r C:\Windows\system32\drivers\etc\hosts") sleep(2000) Local $file = FileOpen("C:\Windows\system32\drivers\etc\hosts",1) Local $command = FileWriteLine($file, "") Local $command = FileWriteLine($file, "ccc.ccc.ccc.ccc www.google.com") RunAs($sUserName,@computername,$sPassword,0,$command) sleep(4000) RunAs($sUserName,@computername,$sPassword,0,"attrib +s +h +r C:\Windows\system32\drivers\etc\hosts") MsgBox(0,"Information","Configuration completed") Edited June 29, 2015 by JRZJulien Link to comment Share on other sites More sharing options...
Blue_Drache Posted June 29, 2015 Share Posted June 29, 2015 (edited) $FO_APPEND is part of the File Operations globals file you probably have to INCLUDE [autoit]#include <FileConstants.au3> [/autoit] Edited June 29, 2015 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache 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