Announcement

Collapse
No announcement yet.

Adding text to host file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding text to host file

    Here is my script:

    attrib c:\windows\system32\drivers\etc\hosts -R
    echo > c:\windows\system32\drivers\etc\hosts
    echo.
    echo 127.0.0.1 localhost
    echo 192.168.8.200 Hostname >> c:\windows\system32\drivers\etc\hosts
    echo 192.168.8.66 Hostname >> c:\windows\system32\drivers\etc\hosts
    ::attrib c:\windows\system32\drivers\etc\hosts +R
    pause
    I want to delete every thing in the hosts file and add the entries I want. Now this works however on the top I get this:

    "ECHO is on" how can I fix that?
    thanks.

  • #2
    Re: Adding text to host file

    Use a dot (a period or a colon) after echo instead of a space. Everything after the dot will be echoed whether it is empty or starts with a space(s).
    When you don't place a dot and you do not enter text after echo, the command wil just return the echo on/off status.

    Code:
    @echo off
    
    (Set HostsFile=%WinDir%\system32\drivers\etc\hosts)
    
    If exist %HostsFile%,(attrib %HostsFile% -R)
    
       echo.# Hosts file managed by script> %HostsFile%
       echo.>>%HostsFile%
       echo.127.0.0.1   localhost>>%HostsFile%
       echo.192.168.8.200   Hostname ^# fileserver>>%HostsFile%
       echo.192.168.8.66   Hostname>>%HostsFile%
    
    If exist %HostsFile%,(attrib %HostsFile% +R)
    
    ::check
    start notepad %HostsFile%
    \Rems


    EDIT
    In the batch above I corrected this typo;
    If exist %$Hosts%,(attrib %HostsFile% +R)
    Last edited by Rems; 7th November 2007, 17:09.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Adding text to host file

      Thank you, Thank you, Thank you, you have no idea how much this helps me. You are a genius.
      cheers

      Comment

      Working...
      X