Solved

Batch file to Copy mutiple files to multiple locations

Posted on 2006-11-28
10
683 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 32

Expert Comment

by:and235100
ID: 18029012
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
ID: 18035863
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
ID: 18036572
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:davystocks
ID: 18037145
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
ID: 18038139
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
 
LVL 4

Author Comment

by:davystocks
ID: 18038655
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
ID: 18038829
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
ID: 18038916
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
ID: 18042498
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
ID: 18045468
That's great. I would never have thought of doing that. Thanks for your help sirbounty.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Copy and Paste Windows 7 Files Not Working 6 108
My Documents Sync to shared location 4 91
Windows 7 and Pro update issues 5 97
Which browser works with XP 16 434
There are 2 things you must have in order to connect to the internet behind a router, The "Gateway IP" of the router, which is usually something like 192.168.xxx.1, I've seen routers with default values of: 192.168.0.1, 192.168.1.1, 192.168.11.1, …
cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

756 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