Page 1 of 1

Copying file to EVERY profile on a machine.

Posted: 25 Mar 2013 12:29
by sourbread
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?

Re: Copying file to EVERY profile on a machine.

Posted: 25 Mar 2013 15:35
by foxidrive
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

Re: Copying file to EVERY profile on a machine.

Posted: 26 Mar 2013 06:48
by sourbread
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!

Re: Copying file to EVERY profile on a machine.

Posted: 30 Mar 2013 12:11
by #dev
hi everyone !
this is maybe a solution for the "users" folder :
cd /d "%userprofile%"
cd..
now you have the folder's exact location (%cd%) !