Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File to copy a folder to multiple PCs

Status
Not open for further replies.

bowflyer

IS-IT--Management
Apr 10, 2006
27
US
Does anyone have a batchfile that would do the following..

1. ask me what is the PC Name
2. copy a designated folder to that new PC that has been identified in the batch file
3. ask if there is another
4. quit if done otherwise ask for another PC


login script in not an option
 
This isn't exactly easy to do with native batch commands, but it can be done. A probably little known fact is that you can do command line options when running a batch file from the command line, which passes the input to respective variables within the batch file. So, for instance, if you have a simple batch file named myping.bat like so:

ping -n 1 %1

You would type the following at the command line to pass the option to the %1 variable:

c:\myping.bat barney

Which would result in a single echo request from "barney".

To do a file copy, your batch file might look something like this if the folder you're copying is static:

xcopy c:\chipfolder \\%1\c$

The command line for this, if your batch file was called mycopy.bat would be:

c:\mycopy.bat barney

My choice, however, would be to use a vbscript with an input box for typing in the destination computer name. That would be much prettier in my opinion. If you want some code for that, it shouldn't be too hard to do.

 
Guess I should have read your request more carefully. My examples above only do one PC at a time, but it's relatively easy to re-run the command with a new computer name. I'll get you some code to do this with vbscript shortly.
 
VBscript would be great!

I just don't have any experience with VB.

where do I start or do you have something already?
 
Shucks, sorry, but I have to run out. These few lines may get you started, but it won't run a loop as is, I'll get that to you if someone else doesn't show you how. Here is one way to do it, this would be your vbscript:

Dim pcName
pcName = Inputbox("Enter Computer Name","Enter Target for Copy")
Set WShell = CreateObject("WScript.Shell")
WShell.Run "c:\scripts\mycopy.bat " & pcName

That will give you a nice popup box to input a computer name, and will then call a batch file, which does the actual copy. I'm pretty sure you can copy folders in vbscript, but I'm not sure if it's the same as copying files. If you do the batch file as I showed you above:

xcopy c:\chipfolder \\%1\c$

The vbscript will call it for you and pass the computer name to the %1 variable. You just have to make sure all the paths match up, e.g. I have the batch file in c:\scripts.
 
so far so good....

but how do I get it to ask me if I want to do another one

if so, return to the beginning or exit
 
One way would be to call the vbscript again from within the batch file. So the batch file would then be:

xcopy c:\chipfolder \\%1\c$
cscript myscript.vbs

I'm sure some expert vbscripters would yell at me for doing it this way, but it would work. You could do a loop within the vbs, but for non-experts like me, this way works just as well. But you'd want to add "on error resume next" to the beginning of your vbs otherwise you'll get a popup yelling at you that your code is wrong.

This will as you for your destination computer name, do the copy, then popup the input box again asking for another computer name. If you don't want to do another one, just his cancel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top