Windows Batch to add a record to hosts file

Tobia picture Tobia · May 27, 2013 · Viewed 11k times · Source

I need a batch file to add a record to hosts file in windows, however I do not need just a file append writing because I would like to check if this record is already present. Is it possibile?

Answer

npocmaka picture npocmaka · May 27, 2013
type "%SystemRoot%\system32\drivers\etc\hosts" | find "my_record" ||echo my_record>>"%SystemRoot%\system32\drivers\etc\hosts"

try this.You'll need administrator permissions to add something in hosts file