Solved

Batch file to Copy mutiple files to multiple locations

Posted on 2006-11-28
10
678 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
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
 
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Old version of iTunes download 4 119
how to Repair Windows XP 12 88
difference between registeries 3 87
different catridges 8 90
If you build your web application in Visual Studio you'll get at least a few binaries, or .DLL, files in your bin folder. However, there is more compiling to be done. Normally this would happen when an ASP.NET resource within the web site is request…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

17 Experts available now in Live!

Get 1:1 Help Now