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\"
EndIf

$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])
Next

 

Edited by hamandpickles
Link to comment
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)

 

#RequireAdmin



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\resetmobile.bat")
        FileDelete($folder&$profile&"\desktop\resetmobile.bat.lnk")
        FileDelete($folder&$profile&"\desktop\resetmobile.lnk")
        FileDelete($folder&$profile&"\desktop\sansiomobileinstall.bat")
        FileDelete($folder&$profile&"\desktop\sansiomobileinstall.bat.lnk")
        FileDelete($folder&$profile&"\desktop\sansiomobileinstall.lnk")
        FileDelete($folder&$profile&"\desktop\HealthEMS Mobile.lnk")
        FileDelete($folder&$profile&"\desktop\HealthEMS Mobile.lnk")
        DirRemove($folder&$profile&"\AppData\Roaming\Sansio\", 1)
WEnd
FileClose($search)
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, 

#RequireAdmin
#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
_FileCreate($TestFile)

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

;Look at Array Contents
_ArrayDisplay($aUsers)

;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)
Next

 

Edited by ViciousXUSMC
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...