Push host file through batch script

  • Thread starter Thread starter fem
  • Start date Start date
F

fem

Hi,

I'm trying to push host file out to the clients pc using
batch script. I have one global batch script and when i
modify that script, i would like to send it out to the
user system32\drivers\etc folder. Since the user don't
have admin rights the host file is not copying over..would
any one know how to do this without giving user admin
rights.

Thanks,
Fem
 
fem said:
I'm trying to push host file out to the clients pc using batch script. I
have one global batch script and when i modify that script, i would like
to send it out to the user system32\drivers\etc folder. Since the user
don't have admin rights the host file is not copying over..would any one
know how to do this without giving user admin rights.

Hi fem,

Your users don't need admin rights; only you do. Just copy the file to:

\\<computername>\ADMIN$\system32\drivers\etc

Of course, replace <computername> as appropriate.

HTH,

Bill
 
Thanks,
but is there any way we can send it all computers instead
of typing in each computer name. Since we have over
300pcs that needs to be updated.

Thanks in advance
 
Thanks,
but is there any way we can send it all computers instead
of typing in each computer name. Since we have over
300pcs that needs to be updated.

This is what login scripts are generally used for. If you are not
currently using them, this might be a good time to implement.

Otherwise, if you just do a NET VIEW (or something similar) and push
files to all those computers, you'll miss out on any computers that
happened to be powered off or otherwise unreachable.

ws
 
fem said:
but is there any way we can send it all computers instead of typing in
each computer name. Since we have over 300pcs that needs to be updated.

Yes. The FOR command is your friend.

First, put the computer names into a text file, one per line; you can use
the NET VIEW command as a starting point; e.g.

NET VIEW > LIST.TXT

Edit the file LIST.TXT and remove the extra lines at the beginning and end
of the file and save it.

Next, use the FOR /F command to parse each line of the file:

FOR /F %%c IN (LIST.TXT) DO @ECHO COPY <yourhostsfile>
\\%%c\ADMIN$\system32\drivers\etc >> DO_IT.CMD

The above two lines are a single command; make sure to type it all one one
line (with a space after your hosts file name).

Last, open the DO_IT.CMD and make sure that it looks right, and that you
are not performing the copy to any machines you did not intend to.

If all is well, you can run the DO_IT.CMD script to make the change. Review
it carefully before running it.

One thing to note is that the above FOR command will not work properly if
you have any computer names that contain a space.

HTH,

Bill
 
I said:
FOR /F %%c IN (LIST.TXT) DO @ECHO COPY <yourhostsfile>
\\%%c\ADMIN$\system32\drivers\etc >> DO_IT.CMD

Oops! The \\ is already there, so the line should actually be:

FOR /F %%c in (LIST.TXT) DO @ECHO COPY <yourhostsfile>
%%c\ADMIN$\system32\drivers\etc >> DO_IT.CMD

HTH,

Bill
 
would this still work if the computer don't have file or
printer share enabled?

thanks again.
I'm using the login batch script...since the users don't
have rights on their computer/domain...they can't copy the
hosts file over to their system32/drivers/etc folder.
 
Bill Stewart said:
Oops! The \\ is already there, so the line should actually be:

And you could filter on that:

@echo off
FOR /F "tokens=1" %%c in ('net view ^|find "\\"') DO (
ECHO COPY <yourhostsfile> >%%c\ADMIN$\system32\drivers\etc >> DO_IT.CMD
)

But this will also give only a snapshot of currently running pc's
 
Matthias Tacke said:
And you could filter on that:

@echo off
FOR /F "tokens=1" %%c in ('net view ^|find "\\"') DO (
ECHO COPY <yourhostsfile> >%%c\ADMIN$\system32\drivers\etc >> DO_IT.CMD
)

This is true, of course; but I wanted to explain step-by-step as the OP
does not seem to have any scripting experience.

Thanks,

Bill
 
Bill Stewart said:
This is true, of course; but I wanted to explain step-by-step as the OP
does not seem to have any scripting experience.
Of course no offense meant Bill, I know your expertise.
My attenttion is more on the tv at the moment, watchung snooker
world champ in Sheffield :-)
 
Hi Fem,

Why not run your script as a machine startup script through Group Policy -
it would solve your admin rights problem.

Jens
 
For NT-class machines (i.e. non Win9x), the computers must have the
"Workstation" service running to be able to copy a file from a central UNC
machine. Else, it must have the "Server" service running for a remote
machine to push files to it via UNC.

--
//David
IIS
This posting is provided "AS IS" with no warranties, and confers no rights.
//
would this still work if the computer don't have file or
printer share enabled?

thanks again.
I'm using the login batch script...since the users don't
have rights on their computer/domain...they can't copy the
hosts file over to their system32/drivers/etc folder.
 
Back
Top