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
Solved

Copy files with a login script

Posted on 2004-09-02
10
272 Views
Last Modified: 2010-04-11
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.
0
Comment
Question by:stylmark
10 Comments
 
LVL 23

Expert Comment

by:rhandels
ID: 11969084
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
 
LVL 1

Expert Comment

by:master_chris
ID: 11969269
@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
 
LVL 76

Expert Comment

by:David Lee
ID: 11969697
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 1

Expert Comment

by:technicvn
ID: 11969959
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
 
LVL 7

Accepted Solution

by:
wparrott earned 250 total points
ID: 11970027
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
 
LVL 3

Expert Comment

by:gnudiff
ID: 11971243
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
 
LVL 8

Expert Comment

by:holger12345
ID: 11978078
@gnudiff:
you may not have blanks in the names of COPYFILES ... (I wouldnt use names with blanks anywhere ;-) )
0
 
LVL 3

Expert Comment

by:gnudiff
ID: 11995591
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
 
LVL 3

Expert Comment

by:gnudiff
ID: 11995605
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
 

Author Comment

by:stylmark
ID: 12011696
Even though some of the other answers would probably had worked wparrott's answer was simple enough.  ThanX to everyone else
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VPS for routing recomendations 3 65
How to configure this in fortinet firewall 2 65
IPv6 NAT to IPv4 28 66
what is mstp 6 37
Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

829 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