Solved

Batch file to Copy mutiple files to multiple locations

Posted on 2006-11-28
10
677 Views
Last Modified: 2012-05-05
I have a script that copies a group of files from a location to the user's profile. I then run this on each machine, whilst logged in under the user's profile. Is it possible for me to run the script remotely so that it does the copying to each user's PC, under the logged-in profile?

<------START------->
@echo on

xCopy "\\servername\source\source.doc" "C:\Documents And Settings\%USERNAME%\destination\" /F /Y
xCopy "\\servername\source2\source2.xls" "C:\Documents And Settings\%USERNAME%\destination\" /F /Y

pause

<------END------->
0
Comment
Question by:davystocks
  • 5
  • 4
10 Comments
 
LVL 32

Expert Comment

by:and235100
Comment Utility
Can'y you just do a startup/logon script?

Just put this in a txt file, rename the extension to .bat, then put this in the logon scripts for domain/or on a local PC by using gpedit.msc?
0
 
LVL 4

Author Comment

by:davystocks
Comment Utility
Thank you for your comment.
I do not want to run the script each time the user logs on. It is a one-time running of the script that I want to be able to execute at will.
I am thinking that I could have a file listing the profiles/machines, that I reference in my script using parameters, however, I am not sure how to do this?
Any help would be greatly appreciated.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
I don't know of a way to get this to the user's 'specific' profile, but you can drop it into the all user's profile...

Generate a list of the computers - computers.txt

Then paste the following into your batch file:

::<---START--->
@echo off
for /f %%a in (C:\computers.txt) do call :process %%a
goto :eof

:process
set wks=%1
xCopy "\\servername\source\source.doc" "\\%wks%\C$\Documents And Settings\All Users\Desktop\" /F /Y
xCopy "\\servername\source2\source2.xls" "\\%wks%\C$\Documents And Settings\All Users\Desktop\" /F /Y

::<--END-->
0
 
LVL 4

Author Comment

by:davystocks
Comment Utility
Thanks sirbounty. That is certainly closer to what I'm looking for, and I can make use of this. Unfortunately, the files do need to go to the profile that is currently logged in to the machine. If no further posts are made that can demonstrate how to do this, I shall award you the points for the above script, as it does bring me closer to success.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Would the user be logged on while you're doing it?  Can you ensure that?  If not, then we may can do it with a little 'trickery'... ;^)
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 4

Author Comment

by:davystocks
Comment Utility
The user would definitely be logged on at the time of running the script
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
Comment Utility
Thought about this - we may have a solution this way...

::<---START--->
@echo off
for /f %%a in (C:\computers.txt) do call :process %%a
goto :eof

:process
set wks=%1
for /f "skip=4 tokens=3 delims=\" %%x in ('reg query "\\%wks%\hkcu\volatile environment" /v HomePath') do set usrPath=%%x
xCopy "\\servername\source\source.doc" "\\%wks%\C$\Documents And Settings\%usrPath%\Desktop\" /F /Y
xCopy "\\servername\source2\source2.xls" "\\%wks%\C$\Documents And Settings\%usrPath%\Desktop\" /F /Y

::<--END-->

Let me know the results...tested okay on this end, but you know, Murphy's Law and all... ;)
0
 
LVL 4

Author Comment

by:davystocks
Comment Utility
Thats work great.....thanks so much.

Could you explain what's happening in:

('reg query "\\%wks%\hkcu\volatile environment" /v HomePath') do set usrPath=%%x

for my own benefit.
Thanks again.

0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Sure - it's a command-line registry query agains the passed workstation name's HKey_Current_User hive.
There's a environment value created called HomePath - the for loop strips out all that we don't need, leaving us with the user's name.
Thanx.
0
 
LVL 4

Author Comment

by:davystocks
Comment Utility
That's great. I would never have thought of doing that. Thanks for your help sirbounty.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now