Batch script to add hosts to Windows hosts file

Discussion in 'Scripting' started by jinvidia, Aug 21, 2016.

  1. jinvidia

    jinvidia MDL Novice

    Aug 7, 2016
    38
    2
    0
    Geeks I need a batch script to add some hosts to Windows 10 hosts file. I tried running the script in administrator mode and also clearing the read only flag from the hosts file but I get access denied error. Please help. Thanks in advance
     
  2. kaljukass

    kaljukass MDL Addicted

    Nov 26, 2012
    814
    268
    30
    Where is this bat or cmd script, what You tried. Usually there should be no problems.
     
  3. sml156

    sml156 MDL Member

    Sep 8, 2009
    123
    62
    10
    #3 sml156, Aug 22, 2016
    Last edited: Aug 22, 2016
    There is no need to write a .bat for what you want to accomplish I have used HostsMan for many years and also Hostserver to take care of my Hosts file, Just make sure you disable DNS Client in services.msc before you try to go to any web page or your page loads will be either slower than molasses in a artic winter or not load at all.

    If your really hell bent on using a .bat file check these site's out
    https://github.com/crazy-max/WindowsSpyBlocker
    https://github.com/StevenBlack/hosts
    https://github.com/jakeogh/dnsgate
    http://someonewhocares.org/hosts/
    http://winaero.com/blog/stop-windows-10-spying-on-you-using-just-windows-firewall/

    Edit:
    You may want to stay away from HpHosts because they are very aggressive in what they chose to block. It's easy to unblock stuff but many people cant be bothered adding an exception to the rules and then resetting their cash to load a page that they Ham-fistedly blocked. they also block Yahoo and many other sites that people actually use and need on a daily basis

    Edit: 2
    I posted a link to Ham-fistedly blocked on TenForums and it got promptly deleted.
    I also posted on Ham-fistedly blocked telling MysteryFCM that TenForums deleted my post, Looking at HpHosts forums I see he deleted my post there, I wonder if MDL will delete this post LOL
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. sebus

    sebus MDL Guru

    Jul 23, 2008
    5,833
    1,748
    180
    hosts commander works well in batch files
    Just take care if running on x64 system (as it best to place it in syswow64 folder)
     
  5. ofernandofilo

    ofernandofilo MDL Member

    Sep 26, 2015
    211
    128
    10
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. JFKI

    JFKI MDL Expert

    Oct 25, 2015
    1,098
    369
    60
    Check this site out, everything you never wanted to know about the windows host file :
    http://winhelp2002.mvps.org/hosts.htm
     
  7. jinvidia

    jinvidia MDL Novice

    Aug 7, 2016
    38
    2
    0
    Sorry for the late reply friends. Finally I found out the solution. It's just converting the batch file to exe and the voila the entries are there in the host file. I know that it can be done with a hosts editor but I wanted to do it with a single click. Anyway thank you very much.