Jump to content

How to add recoder into HOSTS with RunAs in Win7


Recommended Posts

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

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 by Shane0000
Link to comment
Share on other sites

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 by JRZJulien
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...