Copying file to EVERY profile on a machine.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sourbread
Posts: 23
Joined: 26 Apr 2012 09:10

Copying file to EVERY profile on a machine.

#1 Post by sourbread » 25 Mar 2013 12:29

I think I'm really close but I got stuck and figured I would ask you guys...

I have to copy an updated file to every profile on a machine and every future profile getting created.

Code: Select all

for /f "tokens=1,*" %%a in ('dir %systemdrive%\Users' /ad /b) do @xcopy /d /y source "c$\Users\%a\AppData\LocalLow\Sun\Java\Deployment"


I'm certain something is wrong with the for /f statement because running the dir statement alone produces every profile on a machine.

Any ideas?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copying file to EVERY profile on a machine.

#2 Post by foxidrive » 25 Mar 2013 15:35

It is OS specific as some versions of Windows don't have a users folder.

This is the kind of thing you want, but you still have to check if appdata exists and then xcopy as not all profiles have an appdata folder. It won't work on XP and earlier.

@echo off
for /f "delims=" %%a in ('dir "%systemdrive%\users" /ad /b') do xcopy /d /y "c:\folder\files\*.*" "%systemdrive%\users\%%a\AppData\LocalLow\Sun\Java\Deployment\"
pause

sourbread
Posts: 23
Joined: 26 Apr 2012 09:10

Re: Copying file to EVERY profile on a machine.

#3 Post by sourbread » 26 Mar 2013 06:48

Yeah, I'm building the logic in the script to decipher the OS and copy the path accordingly. Looks like the tokens and a few syntax errors were my problem, thanks Foxi! That took care of it all for me!

#dev
Posts: 1
Joined: 30 Mar 2013 12:02

Re: Copying file to EVERY profile on a machine.

#4 Post by #dev » 30 Mar 2013 12:11

hi everyone !
this is maybe a solution for the "users" folder :
cd /d "%userprofile%"
cd..
now you have the folder's exact location (%cd%) !

Post Reply