Scripting HOSTS file

G

Guest

Does anyone know how to insert a line into the hosts file,
from the logon script running against the user account on
the server.

Thank you
 
R

Ray at

echo 123.123.123.123 hostname>>%windir%\system32\drivers\etc\hosts

I believe that the default permissions on this file will not allow an
ordinary to modify the file. Also, you may want to do something that checks
for this entry all ready so you don't fill up the file with redundant
entries.

Ray at work
 
G

Guest

Thank you, that works, but as you stated it puts in
redundant entries, any idea where syntex to check for that
line?
 
W

Wadester

(e-mail address removed) [[email protected]]
posted:
Thank you, that works, but as you stated it puts in
redundant entries, any idea where syntex to check for that
line?

Try:

FINDSTR /I "123.123.123.123" %WINDIR%\SYSTEM32\DRIVERS\ETC\SERVICES >NUL
IF %ERRORLEVEL%==1 ECHO. >> %WINDIR%\SYSTEM32\DRIVERS\ETC\SERVICES&&ECHO
123.123.123.123 hostname >> %WINDIR%\SYSTEM32\DRIVERS\ETC\SERVICES

ws
 
G

Guest

Thank you, with several modification I got the script to
work. I appreciate the help.

-----Original Message-----
(e-mail address removed) [[email protected]]
posted:

Thank you, that works, but as you stated it puts in
redundant entries, any idea where syntex to check for that
line?

Try:

FINDSTR /I "123.123.123.123" %WINDIR%\SYSTEM32 \DRIVERS\ETC\SERVICES >NUL
IF %ERRORLEVEL%==1 ECHO. >> %WINDIR%\SYSTEM32 \DRIVERS\ETC\SERVICES&&ECHO
123.123.123.123 hostname >> %WINDIR%\SYSTEM32 \DRIVERS\ETC\SERVICES

ws

--
The sea was angry that day, my friends. Like an old man, trying to send
back soup at a deli.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top