Solved

Batch file to Copy mutiple files to multiple locations

Posted on 2006-11-28
10
685 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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, …
Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 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