PDA

View Full Version : Computers how to write a batch file


tymania
07-01-2010, 07:59 AM
To all you programmers out there.. i am horrible at writing batch files i need some assistance writing a batch file to edit the host file under C:\windows\system32\drivers\etc
I need the batch file to add a line to the host file. Here is the line i need added
192.168.1.8 www.vodec.org

I appreciate any help with this matter

phisherman
07-01-2010, 08:03 AM
Are you trying to do this on multiple machines?

tymania
07-01-2010, 08:04 AM
Are you trying to do this on multiple machines?

i am going to attach the file to a GPO so it will run when each user logs in

tymania
07-01-2010, 08:05 AM
Are you trying to do this on multiple machines?

yes it will be multiple machines

Molitoth
07-01-2010, 08:16 AM
edited, oops.

phisherman
07-01-2010, 08:22 AM
I would use a wise script to do this, but I'm sure you could easily do it with a vb script.

tymania
07-01-2010, 08:23 AM
I would use a wise script to do this, but I'm sure you could easily do it with a vb script.

yeah i did some googling and found out that a vb script is prob the way to go.. i saw an example of one.. looks complicated to write

phisherman
07-01-2010, 08:39 AM
It's going to be something like this, though this script is a little more thorough. This will check for the existence of the vodec line and won't append if it's already there. As long as it's not there, then it will append. This should be in batch file format by the way.

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS

SET ADDHOST=192.168.1.8 www.vodec.org

SET HOSTS=%windir%\system32\drivers\etc\hosts
SET FOUND=FALSE

FOR /F "delims=^n tokens=*" %%a IN (%HOSTS%) DO (IF "%%a"=="%ADDHOST%" SET FOUND=TRUE)
MOVE /Y %tmp%\hosts %HOSTS%
IF %FOUND%.==TRUE. (ECHO %ADDHOST% is present in HOSTS) ELSE (ECHO %ADDHOST%>>%HOSTS%)

phisherman
07-01-2010, 08:41 AM
syntax may be a little bit off, but i don't write batch files too often. please test it fully before deployment if you use it.

Fish
07-01-2010, 08:48 AM
syntax may be a little bit off, but i don't write batch files too often. please test it fully before deployment if you use it.

Too late, it's been sent to 3000+ workstations..... :thumb:

tymania
07-01-2010, 08:56 AM
Too late, it's been sent to 3000+ workstations..... :thumb:

lolololol

i will give it try on my local computer first

tymania
07-01-2010, 09:03 AM
phisherman.. you da man!! IT WORKS! thank you so much i really appreciate it!

phisherman
07-01-2010, 09:12 AM
no prob.