Would like a script to replace host file

  • I would like a script to replace the hosts file on all workstations. Has anyone done this or does one already exist?

    Legacy Forum Name: Would like a script to replace host file,
    Legacy Posted By Username: GPotvin

  • Script Name: Deploy Hosts and LMHosts
    Script Description:

    IF True
    THEN
    Write File
    Parameter 1 : %systemroot%\system32\drivers\etc\hosts
    Parameter 2 : VSASharedFiles\Client Specific\hosts
    OS Type : 0
    Write File
    Parameter 1 : %systemroot%\system32\drivers\etc\lmhosts
    Parameter 2 : VSASharedFiles\Client Specific\lmhosts
    OS Type : 0
    Execute Shell Command
    Parameter 1 : nbtstat -R
    Parameter 2 : 1
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Hosts and LMHosts added and refreshed.
    OS Type : 0
    ELSE


    Just upload your hosts file to the kserver, and do the above. This script also does the lmhosts file, but you can delete that step if you don't need it.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen
  • Thank you. Made my day!

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: GPotvin
  • OK. The script works fine and I added to it to flush DNS. The only issue I am finding is that software like SpyBot S&D changes the Hosts file attributes to 'Read Only". Is there a way to add to the script so that the file attribute is changed to "Read/Write" first, then run the rest of the script?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: GPotvin
  • GPotvin
    OK. The script works fine and I added to it to flush DNS. The only issue I am finding is that software like SpyBot S&D changes the Hosts file attributes to 'Read Only". Is there a way to add to the script so that the file attribute is changed to "Read/Write" first, then run the rest of the script?


    Add the command attrib -R FILENAME to the script to remove the Read Only attribute of the file.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: pcmnetmanage
  • I'm sorry, but I do not know where to add this attribute.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: GPotvin
  • Using the above example:


    Script Name: Deploy Hosts and LMHosts
    Script Description:

    IF True
    THEN
    Execute Shell Command
    Parameter 1 : attrib -R %systemroot%\system32\drivers\etc\hosts
    Parameter 2 : 0
    OS Type : 0
    Write File
    Parameter 1 : %systemroot%\system32\drivers\etc\hosts
    Parameter 2 : VSASharedFiles\Client Specific\hosts
    OS Type : 0
    Write File
    Parameter 1 : %systemroot%\system32\drivers\etc\lmhosts
    Parameter 2 : VSASharedFiles\Client Specific\lmhosts
    OS Type : 0
    Execute Shell Command
    Parameter 1 : nbtstat -R
    Parameter 2 : 1
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Hosts and LMHosts added and refreshed.
    OS Type : 0
    ELSE


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: pcmnetmanage
  • Reset Host File.zip
    The method above will work however there are differences between say Windows XP default Hosts file and Windows Vista, then more differences for Windows 7 which the above script does not cover.

    Though I understand a Windows XP Hosts file will work for the most part on the later machines there is issues so I would advise sticking with the originals which I have included along with TWO SCRIPTS...

    The first Script is to reset the host files to default and gets used with the attached hosts files, simply copy the folder "Host Files" into your shared folder directory and upload the script.

    The second script is an example of how we change our hosts files for blocking sites, the example attached is for Social Networking sites. There is not a lot changed from the default script included however we found that adding sections (Header & Footer) to the top and bottom of each section when something is added it makes for much easier management, we have also done similar for the Known IE Exploit sites blocking.

    Any questions feel free to ask.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Hoe