• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Help me about a .bat script...

Status
Not open for further replies.
Level 9
Joined
Oct 11, 2009
Messages
477
I'm trying to edit "HOSTS" file in Windows that is located at C:/Windows/system32/drivers/etc/hosts using a .bat script for convenience, because when you enter any domain there, it will be blocked...

I already searched Google but can't barely understand, maybe someone can help me to create a script for that and a few guides... Your help will be appreciated...

BTW, I want to block the domain "BOX.ANCHORFREE.NET"...
 
Level 11
Joined
Feb 14, 2009
Messages
884
If you run into any problems when executing Ironside's script, try executing it with administrative privileges.
 
Level 9
Joined
Oct 11, 2009
Messages
477
This should do it.

Code:
echo 127.0.0.1 BOX.ANCHORFREE.NET >> C:\Windows\System32\drivers\etc\hosts

After I executed the .bat file, it seems that the HOSTS file remain that way? :vw_wtf:

hostss.png
 
Level 9
Joined
Oct 11, 2009
Messages
477
You might need administrative privileges to be able to write to \hosts.
Also, you have misspelled the ">>" as ">", which will try to replace the content with "127.0.0.1 BOX.ANCHORFREE.NET"

That much from your picture, that silly circle might be blocking the other ">" however.

I've blocked the other ">" by the red circle.... :vw_death:

Anyway, I have the administrative privileges when I execute the script, but still, nothing happens... :(
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Why not manually type it in the host file?

127.0.0.1 BOX.ANCHORFREE.NET

Just make sure you have write access to the file...
 
Level 11
Joined
Feb 14, 2009
Messages
884
When I said "execute it with administrative privileges", I meant right-click -> Run as Administrator, not that the current user should have administrative privileges.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Hmmm....

You're doing this in your batch file:

Code:
echo 127.0.0.1 BOX.ANCHORFREE.NET -> C:\Windows\System32\drivers\etc\hosts

but shouldn't this be:

Code:
echo 127.0.0.1 BOX.ANCHORFREE.NET >> C:\Windows\System32\drivers\etc\hosts

A single > will overwrite the text file, a >> will append to an existing file. Where did you read to use ->?
 
Level 9
Joined
Oct 11, 2009
Messages
477
Hmmm....

You're doing this in your batch file:

Code:
echo 127.0.0.1 BOX.ANCHORFREE.NET -> C:\Windows\System32\drivers\etc\hosts

but shouldn't this be:

Code:
echo 127.0.0.1 BOX.ANCHORFREE.NET >> C:\Windows\System32\drivers\etc\hosts

A single > will overwrite the text file, a >> will append to an existing file. Where did you read to use ->?

No! That's exactly what I copied, I think I've messed up my screenshot... :vw_death:

hosts2.png
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Then if you have full permissions and read/write access, try turning off kaspersky for a while and then run the .bat file.
See if that works.
If it doesn't change then it gets blocked, and this would either be by another third party, or by administrative priviliges, or by not having propper access to the file.
So it should be one of these things causing it not to add the extra line.

You have already checked the property's of the file to see if you have read/write access and to see if you have administrative priviliges?
Then turn off kaspersky and run the .bat again. See if that helps.

If it still doesn't, download process explorer and check which process is attached to the file causing it not to be writeable.
 
Level 9
Joined
Oct 11, 2009
Messages
477
Then if you have full permissions and read/write access, try turning off kaspersky for a while and then run the .bat file.
See if that works.
If it doesn't change then it gets blocked, and this would either be by another third party, or by administrative priviliges, or by not having propper access to the file.
So it should be one of these things causing it not to add the extra line.

You have already checked the property's of the file to see if you have read/write access and to see if you have administrative priviliges?
Then turn off kaspersky and run the .bat again. See if that helps.

If it still doesn't, download process explorer and check which process is attached to the file causing it not to be writeable.

Thank you, Kaspersky is blocking the attempt in modifying the system file... :grin:

Thanks also for everyone in helping me! God bless you all! :)
 
Status
Not open for further replies.
Top