How to edit hosts file on XP?

(imported topic written by DC2308)

Hi All - I’m trying to edit the host file at “C:\WINDOWS\system32\drivers\etc” and need to just simply add an additional line with IP address to host name. This is what I came up with:

Action Script:

download http://RTNCBFX01.siemensgovt.com:52311/Uploads/0329bc06a6bc4795500d6cca6835dff2a4b122a3/hosts.tmp

continue if {(size of it = 488 AND sha1 of it = “0329bc06a6bc4795500d6cca6835dff2a4b122a3”) of file “hosts.tmp” of folder “__Download”}

extract hosts.tmp

delete __Download\hosts.tmp

copy “__Download\hosts.tmp” “{name of drive of windows folder}\WINDOWS\system32\drivers\etc\hosts.tmp”

Log Error:

"Command failed (Copy of ‘__Download\hosts.tmp’ to ‘C:\WINDOWS\system32\drivers\etc\hosts.tmp’ failed (2)) copy “__Download\hosts.tmp” “C:\WINDOWS\system32\drivers\etc\hosts.tmp” (fixlet 4223)

I believe this error means it cannot add new host file because the original still exists. What is the action script to delete the original hosts file and then replace with new one I created? Or is there an easier way to do this?

(imported comment written by SystemAdmin)

Make sure you test this carefully.

download http://RTNCBFX01.siemensgovt.com:52311/Uploads/0329bc06a6bc4795500d6cca6835dff2a4b122a3/hosts.tmp

continue if {(size of it = 488 AND sha1 of it = “0329bc06a6bc4795500d6cca6835dff2a4b122a3”) of file “hosts.tmp” of folder “__Download”}

extract hosts.tmp

delete __Download\hosts.tmp

move “{name of drive of windows folder}\WINDOWS\system32\drivers\etc\hosts” “{name of drive of windows folder}\WINDOWS\system32\drivers\etc\hosts.backup”

copy “”{(pathname of client folder of current site)}__Download\hosts" “{name of drive of windows folder}\WINDOWS\system32\drivers\etc\hosts”

(imported comment written by SystemAdmin)

use system folder instead:

download http://RTNCBFX01.siemensgovt.com:52311/Uploads/0329bc06a6bc4795500d6cca6835dff2a4b122a3/hosts.tmp

continue if {(size of it = 488 AND sha1 of it = “0329bc06a6bc4795500d6cca6835dff2a4b122a3”) of file “hosts.tmp” of folder “__Download”}

extract hosts.tmp

delete __Download\hosts.tmp

move “{system folder}\drivers\etc\hosts” “{system folder}\drivers\etc\hosts.backup”

copy “”{(pathname of client folder of current site)}__Download\hosts" “{system folder}\drivers\etc\hosts”

(imported comment written by SystemAdmin)

download http://RTNCBFX01.siemensgovt.com:52311/Uploads/0329bc06a6bc4795500d6cca6835dff2a4b122a3/hosts.tmp

continue if {(size of it = 488 AND sha1 of it = “0329bc06a6bc4795500d6cca6835dff2a4b122a3”) of file “hosts.tmp” of folder “__Download”}

extract hosts.tmp

delete __Download\hosts.tmp

delete “{system folder}\drivers\etc\hosts.backup”

move “{system folder}\drivers\etc\hosts” “{system folder}\drivers\etc\hosts.backup”

copy “”{(pathname of client folder of current site)}__Download\hosts" “{system folder}\drivers\etc\hosts”

(imported comment written by DC2308)

Thanks Stew for the help but these resulted in the same log error.

I did more research on forum and found this which worked!

Action Script: LINK:

http://forum.bigfix.com/viewtopic.php?id=5990

waithidden cmd.exe /C echo.{“X.X.X.X hostname.com”} >> {(pathname of system folder as string & “\drivers\etc\hosts”)}

Relevance: LINK:

http://forum.bigfix.com/viewtopic.php?id=748

not exists file “hosts” whose (exists lines whose (it as left trimmed string does not start with “#” and it contains “X.X.X.X” ) of it OR exists lines whose (it as left trimmed string does not start with “#” and it as lowercase contains “hostname.com” ) of it) of folder “drivers\etc” of system folder

X.X.X.X is your IP address and hostname.com is the hostname you want to add.