Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch file to Copy mutiple files to multiple locations

Posted on 2006-11-28
10
Medium Priority
?
686 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 1000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
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…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

670 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