Page 1 of 1

Batch file help needed

Posted: 2004-11-24 06:15pm
by Laird
I've been given the task of creating a batch file to copy a users "favorites", thats all fine and dandy...(I can copy fine.) my problem is I had can't figure out how to do this with out having it be a specific users name.

Instead of the batch saying something like this.

"Copy C:\Documents and Settings\laird\favorites\ O:\backup"

I need it to automatically do this without having to write each and every indivdual user name for each batch file.

So should it be something like?
"Copy C:\Documents and Settings\"username"\favorites\ O:\backup"

Or

"Copy C:\Documents and Settings\"*.*"\favorites\ O:\backup"?

Help and the answer would be greatly apperciated....

Posted: 2004-11-25 12:54am
by Mad
Simple method:

Code: Select all

copy "C:\Documents and Settings\%1\favorites\" O:\backup
When you run the batch file, give it the parameter of ther username. So "testbatch laird" would replace %1 with "laird" while "testbatch Administrator" would replace %1 with "Administrator".

To get more complicated, you can try playing around with the FOR command.

Posted: 2004-11-25 12:59am
by phongn
Make a batch file with something like this:

Code: Select all

@ECHO OFF

FOR /R /D %%G IN (*FAVORITES) DO XCOPY /E /Q "%%G" "O:\BACKUP%%~pGFavorites\"
Run that batch program from within the Documents and Settings folder. Test this on a machine that isn't critical first :P It won't copy an empty Favorites folder, unfortunately.

Posted: 2004-11-25 02:24pm
by Laird
Well I got the program running, I just need to know how to get it to activate when a user logs off.(I know I can run it as a scheduled task..when a user logson.).

Any ideas?

Posted: 2004-11-25 10:54pm
by phongn
Learn the magic of Group Policies, there you will find your answer.