Jump to content

copy folder to all users x p and 7

Recommended Posts


I am trying to copy files to existing user profiles. The issue is when running a program(website) the configuration is done on the user level. What I have found is if I can copy the folder that I need to other profiles it works no problem. I have tried to copy the folder to AppData for both the default and admin accounts, the only success I have had with this is for new users which would be correct. What I am also seeing about 50% of the time I can get most of the folders there just not the last folder with all the sub folders containing data. Here is what I am referring to in the default profile c:\Users\Default\AppData\Roaming\program folder\device folder\device settings folder\settings name(here is where the problem start)\settings dll . When the folders do decide to create themselves I am missing everything after device settings for existing users. 

I need to to do this for our entire environment with an unknown number of users on each machine. This is being done as the vendor has stopped supporting our default version browser, luckily they are supporting another browser so we don't have a huge headache. Ultimately what I am trying to do here is push chrome to all of our computers with the addition to adding these folders for all existing users. I have the chrome push working now I just need to add this piece and I am almost done.

side note if anyone has ever pushed out chrome enterprise with the legacy extension this is basically what I am trying to accomplish. 

Here is what we have come up with to view all the users just having trouble copying

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

$ProfileDirectory = "C:\Users\"
if(@OSVersion = "WIN_XP") Then
    $ProfileDirectory = "C:\Documents and Settings\"

$profileArray = _FileListToArray($ProfileDirectory, Default, 2, True)

For $i = 1 to $profileArray[0]

    DirCopy("C:\folder\folder\folder", @AppDataCommonDir & "\modules", 1) --> this is what I am trying to use to copy

MSGBOX(0, "Test", $profileArray[$i])


Edited by hamandpickles

Share this post

Link to post
Share on other sites

Anything in the Default user profile will only apply to new users, so you need to create something to push to existing users as well.

I'll post a script I did that deletes data from all user profiles, you can probably use this method and just use "copy" instead of "delete" 

Another thing to think of is writing a startup script so that when each user logs in it just runs and copies the files for them this way you can just write a more simple version of the script pointing to the users app data folder.  You can make it a bit better by adding a registry check to see if it has run previously for the user so it wont run each login (or just put it in the RunOnce location)



If MsgBox(4, "Black Magic Automation", "Are You Sure You Want To Completely Remove Sansio From This Computer?") = 7 Then Exit

;StringLeft Count From Left Return String w/ Count  Example C:\Users\it022565
;StringInStr Returns Position of String search for \ substring 0 -1 to search from right side.
$folder = StringLeft(@UserProfileDir,StringInStr(@UserProfileDir,"\",0,-1))
;$folder = example C:\Users
$search = FileFindFirstFile($folder&"*")
;FileFindFirstFile returns handle for search
;FilefindNextFile goes through results of search using handle.

While 1
    $profile = FileFindNextFile($search)
        If @error Then ExitLoop
        FileDelete($folder&$profile&"\desktop\HealthEMS Mobile.lnk")
        FileDelete($folder&$profile&"\desktop\HealthEMS Mobile.lnk")
        DirRemove($folder&$profile&"\AppData\Roaming\Sansio\", 1)
DirRemove("C:\Sansio\", 1)
MsgBox(0, "Black Magic Automation", "Cleanup Completed!")

Edit: Also should mention this is before I was comfortable with Arrays.  FileListToArray() and using a For loop could do this probably much cleaner and would be my prefered method should I re-write this in the future.


Edit2: I see your issue, I only saw your bold code before not all the other stuff (Use the Code Tags) So you already have a loop but your just repeating the same copy over and over using the common dir instead of the user specific dir.  Your going to need to incorporate your $profilearray varible that cycles through the user profile names into the copy somewhere similar to my example above so that you can push those files to each users specific app data location and not just the singular common (default user) location. 


I just threw this together and tested.  It works as I wanted and should show you what I was talking about.  You will need to change your paths and such, 

#Include <File.au3>
#Include <Array.au3>
#Include <FileConstants.au3>

;Declare Our Test File Path
$TestFile = @TempDir & "\apptest.txt"

;Declare XP vs 7/8/10 Location For Profiles
$vProfilePath = "C:\Users"
If StringInStr(@OSVersion, "XP") Then $vProfilePath = "C:\Documents and Settings"

;Create a File For Testing

;Put All User Profile Names in an Array
$aUsers = _FileListToArray($vProfilePath, "*", $FLTA_FOLDERS, True)

;Look at Array Contents

;Copy Once to All Users (Default Profile)
FileCopy($TestFile, @AppDataCommonDir, $FC_OVERWRITE + $FC_CREATEPATH)

;Loop Through All User Profiles Doing Copy
For $i = 1 to $aUsers[0]
    FileCopy($TestFile, $aUsers[$i] & "\AppData\", $FC_OVERWRITE + $FC_CREATEPATH)


Edited by ViciousXUSMC
  • Like 1

Share this post

Link to post
Share on other sites

Oh and just incase you didnt know pretty sure "AppData" is "Application Data" on XP so you need to put a varible in for that as well.

I just finally got the last of our XP machines of the network so I can finally stop making dual scripts like that :)

Share this post

Link to post
Share on other sites

Thanks for the post I am going to take a look as it now, I'll let you know what comes of it.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.