Copy files with a login script

There are 3 files that reside at the C:\Documents and Settings\Default User\Application Data\"my application"  folder. I need to copy these 3 files from the mentioned location to C:\Documents and Settings\User A\Application Data\"my application folder.  The real problem is that I need to do this on about 50 computers and these computers are loged in by several users during the day.  Each user needs to have those files in their own profile user a, user b, user c etc.

Does any body know the sintax to accomplish this kind of task using a login script?  Ithe problem I have is that I don't know who is going to log in to what computer and to copy manually those files will be a big task.

My idea is,  at login to execute something like this copy C:\Documents and Settings\Default User\Application Data\My application\*.* C:\Documents and Settings\variable user\Application Data\my application\  What is the sintax for "variable user so it piks up the user name from the windows 2000 user name that is logged in.

ThanX for any help or ideas.
stylmarkAsked:
Who is Participating?
 
wparrottConnect With a Mentor Commented:
Try this in your login script:

@echo off
REM Check for directory 1st
if not exist C:\Documents and Settings\%username%\Application Data\"my application" mkdir C:\Documents and Settings\%username%\Application Data\"my application"

REM Check for 1st file
if not exist C:\Documents and Settings\%username%\Application Data\"my application"\file1 copy C:\Documents and Settings\Default User\Application Data\"my application"\file1 C:\Documents and Settings\%Username%\Application Data\"my application"\file1

REM Check for 2nd file
if not exist C:\Documents and Settings\%username%\Application Data\"my application"\file2 copy C:\Documents and Settings\Default User\Application Data\"my application"\file2 C:\Documents and Settings\%Username%\Application Data\"my application"\file2

REM Check for 3rd file
if not exist C:\Documents and Settings\%username%\Application Data\"my application"\file3 copy C:\Documents and Settings\Default User\Application Data\"my application"\file3  C:\Documents and Settings\%Username%\Application Data\"my application"\file3

REM Continue with rest of login script


This will first check to see if the file exists or not, and if not, copy it from the \default user location to the currently logged in user's location. Of course, replace "my application" with the name of the folder you will be copying from.

Hope this helps...
0
 
rhandelsCommented:
Hi,

First off all, create a batch file, that's called something like copy.bat, then add these rules

copy C:\Documents and Settings\Default User\Application Data\"my application" C:\Documents and Settings\User A\Application Data\"my application folder

Create a rule for each file you need to copy. You can add these rules in the loginscript they allready have..
0
 
master_chrisCommented:
@echo off

rem --- Begin Copy from Backup Directory to Local Drive
xcopy /v /c /i /h /r /y c:\*.* c:\mydata
echo "Copy has been Complete"

**note** Xcopy uses the old command prompt, so make sure u state the directory's properly. example
c:\docume~1\alluse~1\

0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
David LeeCommented:
Here's a script, VBScript, that'll copy the files.  Edit the scipt and change this line

    arrFiles = Array("FileOne.txt", "FileTwo.txt", "FileThree.txt")

substituting your filenames in place of mine.  I tested the script to make sure it works correctly, it did.  I didn't have a chance to test it in a login script though so I'm not sure if it'll be able to read the USEREPROFILE environment variable at that point.  I'm not sure at what point in the login process the environment variables get set.  If it doesn't work from the login script, then you could add it to each user's startup folder.  It should run fine from there.

Dim objFSO
Dim objShell
Dim objEnviron
Dim arrFiles
Dim intItem
Dim strSourcePath
Dim strDestPath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objEnviron = objShell.Environment("PROCESS")
strSourcePath = "C:\Documents and Settings\Default User\Application Data\My Application\"
strDestPath = objEnviron("USERPROFILE") & "\Application Data\My Application\"
wscript.echo strdestpath
arrFiles = Array("FileOne.txt", "FileTwo.txt", "FileThree.txt")
For intItem = 0 To 2
    objFSO.CopyFile strSourcePath & arrFiles(intItem), strDestPath & arrFiles(intItem)
Next
Set objEnviron = Nothing
Set objShell = Nothing
Set objFSO = Nothing
0
 
technicvnCommented:
Hi,
You could follow this instruction to gain your purpose  :
Create a new text file. Open it and type the following command:
@ echo off
Copy /Y \\your_PC_address\C$:\Documents and Settings\Default User\Application Data\My application\*.*  C:\Documents and Settings\variable user\Application Data\my application\
@ echo on
(The parameter /Y means: Suppresses prompting to confirm you want to overwrite an existing destination file)
Then save it as batch file, ex: Copy.bat
Then in user's profile, set this script.
That's all
Regards,
TeK
0
 
gnudiffCommented:
And finally yet another script,, add this to the login script, obviously you need to replace the COPYFILES with the names of the files you want to copy:

Works on my W2K:

SET COPYFILES=firstfile secondfile thirdfile
SET APPDIR=my application
SET GLOBALDIR=C:\Documents and Settings\Default User\Application Data\%APPDIR%
SET USERDIR=%USERPROFILE%\Application Data\%APPDIR%

FOR %%I IN (%COPYFILES%) DO COPY %GLOBALDIR%\%%I %USERDIR%
0
 
holger12345Commented:
@gnudiff:
you may not have blanks in the names of COPYFILES ... (I wouldnt use names with blanks anywhere ;-) )
0
 
gnudiffCommented:
i would have to check again, but i think it worked fine.
an alternative would be to put the contents of the variable in quotes, like:

FOR %%I IN (%COPYFILES%) DO COPY "%GLOBALDIR%"\%%I "%USERDIR%"
0
 
gnudiffCommented:
oh, I think I got what you mean now, holger -- the COPYFILES variable uses blanks to separate file names, of course. It is meant to copy THREE files, each with a name without a blank.
If you need to copy files with blanks, you can put them in quotes perhaps too, like:

SET COPYFILES="first file" secondfile thirdfile

but not sure whether that'd work.
0
 
stylmarkAuthor Commented:
Even though some of the other answers would probably had worked wparrott's answer was simple enough.  ThanX to everyone else
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.