Solved

Copy files with a login script

Posted on 2004-09-02
10
269 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

What’s a web proxy server? A proxy server is a server that goes between clients and web servers, used in corporate to enforce corporate browsing policy and ensure security. Proxy servers are commonly used in three modes. A)    Forward proxy …
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…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now