Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Script to Copy Files/Folders to All the User Profiles on the Machine

Created: 12 Dec 2008 • Updated: 12 Dec 2008 | 17 comments
Eshwar's picture
+30 30 Votes
Login to vote

This is a particular case where we have multiple profiles exist on a single machine. For example several Help Desk personal may use a single machine in rotating shifts.

If we want to copy files/folders to all the user profiles [except default profiles like admin, administrator, newuser, all users, default user etc...] then following is the script that will help in identifying multiple profiles on the machine and copying files/folders to those profiles.

You need to specify the source folder where you have kept your files to be copied.

Note: If you are planning to run this script as part of software delivery task, follow the instructions below.
  • Make sure that Source folder and script lies in the same location
  • Modify the script to look for the source folder in CURRENT FOLDER
'GET CURRENT FOLDER PATH
oFolder1 = fso.GetParentFolderName(WScript.ScriptFullName)
If Right(oFolder1, 1) <> "\" Then oFolder1 = oFolder1 & "\"

Good luck.

Thanks,
Eshwar

License: AJSL
By clicking the download link below, you agree to the terms and conditions in the Altiris Juice Software License
Support: User-contributed tools on the Juice are not supported by Altiris Technical Support. If you have questions about a tool, please communicate directly with the author by visiting their profile page and clicking the 'contact' tab.

Comments 17 CommentsJump to latest comment

Stevo77's picture

I've amended the script to send a ppt file to every users profile. However it is not copying the file and the script doesn't error.

Can anyone help?

Dim fso 
Dim oFolder1, objFolder, oFolder
Dim path
Dim WSHShell
Dim colFolders
Dim sDocsAndSettings 
Dim strComputer

strComputer = "."

Set WSHShell = CreateObject("WScript.Shell")
Set fso = createobject("Scripting.FileSystemObject")

'SPECIFY THE PATH OF THE FOLDER IN WHICH SOURCE FILES RESIDE
Set oFolder1 = fso.GetFolder("c:\Template")

'COPY FILES TO USER PROFILES
sDocsAndSettings = "C:\Documents and Settings"   
Set colFolders = fso.GetFolder(sDocsAndSettings) 

For Each oFolder In colFolders.SubFolders
	Select Case LCase(oFolder.Name)
		Case "admin", "administrator", "newuser", "all users", "default user.original", "localservice", "networkservice"
			'LEAVE THE DEFAULT PROFILES ON THE MACHINE
		Case Else
			' Check for the path
			If fso.FolderExists(sDocsAndSettings & oFolder.Name & "\Application Data") Then
				'COPY FOLDER TO USER PROFILE
				fso.CopyFolder oFolder1, sDocsAndSettings & oFolder.Name & "\Application Data\Microsoft\Templates" ,True
			End If
	End Select 
Next

Set fso = Nothing
Set WSHShell = Nothing

+4
Login to vote
Eshwar's picture

Stevo77,
Sorry for the late reply.
You forgot to mention "\" in the script.
Here it is

sDocsAndSettings = "C:\Documents and Settings"

You should keep "\" at the end like below

sDocsAndSettings = "C:\Documents and Settings\"

Now your script will work like a Champ.

Good luck.
Eshwar

Cheers,

Eshwar

+15
Login to vote
visu2212's picture

Hi Eshwar,

I am having the same kind of requirement but targetted on different OS (xp, Vista & Win7)

The requirement is as follows:

My Installer will copy files to %AppData%\Microsoft\Word\STARTUP - to the profile which the user logged in.

The challenge is-------

If I logged in as a Test User, which doesnt have the elivated privilage to continue the Installation - member of Administrator group.

During Installation the Installer prompts to provide the Administrator password. Provided the Test User provides the Administrator Password, the installation will continue.

But the template files are getting copied under Administrators User Profiles instead of Test User Profile.

Administrators User Profile Location    - C:\Users\Administrator\AppData\Roaming\Microsoft\Word\STARTUP

Test User Profile Location                    - C:\Users\Test User\AppData\Roaming\Microsoft\Word\STARTUP

Note: the same files are available under %AllUsersProfile%\Locale\WordTemplates

I want to have the files available in the LoggedIn user Profile. Can you please provide a script to do the above. Thank you very much for the extended support.

 

Thanks,

Viswanadh M

viswanadh.m@gmail.com

 

 

0
Login to vote
QuietLeni's picture

visu2212,

This sounds like you have UAC switched on within Vista and 7. Certain parts of the hard disk are now off-limits to ordinary users (and this includes paerts of the users' own profiles!)

The problem is that this is a security issue and not something easily done (if at all possible) in a script. When you provide the Administrator password, the installer is then running inside the Administrator's user, which is why you are getting it created in the Administrator's Profile.

If you were to call the script with the end-user's entry of %USERPROFILE% such as:

wscript.exe login.vbs "%USERPROFILE%"

and then, in the script, read the parameter like this:

Dim objArgs, sTargetDir

Set objArgs = WScript.Arguments

sTargetDir = objArgs(0) & "\AppData\Roaming\Microsoft\Word\STARTUP"

Then you can use "sTargetDir" as the variable that holds your target directory for the copy.

Your main problem will be if UAC gets in the way, though.

Hope that this helps.

Kindest regards,

QuietLeni

What is the point of an Asset Management Solution that needs excessive management? Let me help you.

0
Login to vote
Najmul's picture

Hi Eshwar,

The above script is working fine with me, however I need to change the source location from local

'SPECIFY THE PATH OF THE FOLDER IN WHICH SOURCE FILES RESIDE
Set oFolder1 = fso.GetFolder("c:\Template")

to somthing like network share folder can you gudie me for that.

I have tried changing the local folder with network share but it was failed

'SPECIFY THE PATH OF THE FOLDER IN WHICH SOURCE FILES RESIDE
Set oFolder1 = fso.GetFolder("\\192.168.1.200\Template")

this folder is shared to everyone with security perm to everyone.

 

Thanks.

 

0
Login to vote
Steve_H45's picture

First off I hope this post is still monitored since I would like to expand on this copy process and second the script is awesome.  It is what I have been looking for to finally get into the user profiles.  I like how it ignores specified profiles.

I am not technical in vbs but have hacked the above to work with what we need.  I get the logical steps but not the technical language.  The areas I would like to expand on are:

If the folder does not exist, create it, then copy files (we would like to add a folder in the users My Documents folder such as "Production")

If the folder exists and already has files, replace them (specfically the internet Explorer favorites)

Copy and replace a single file  (the idea being that on our users desktop we have shortcuts pointing to servers/resources and we want to replace those links to point to other servers/resources)

Any assistance would be greatly appreciated.
Thanks

0
Login to vote
QuietLeni's picture

Steve_H45,

What have you got at the moment with your script? It is easier to work from what you have at the moment, rather than a previous version.

Regards,

QuietLeni

What is the point of an Asset Management Solution that needs excessive management? Let me help you.

0
Login to vote
Steve_H45's picture

QuietLeni:
Thanks for looking at my issue.  I use the same script in the above post.  I just changed the paths.  It just needs the section in there that if the folder does not exist then create it (and even sub folders if possible) and copy the files down.  I dont know much about VB right now but picking up on tidbits here and there.   The more advanced stuff like replacing the contents of the folder (overwrite) and copying an individual file, I am sure the script could be easily adapted for, and even deleting a directory.  There is a post after yours that has code so I will look at it and learn more.

Thanks

Dim fso
Dim oFolder1, objFolder, oFolder
Dim path
Dim WSHShell
Dim colFolders
Dim sDocsAndSettings
Dim strComputer

strComputer = "."

Set WSHShell = CreateObject("WScript.Shell")
Set fso = createobject("Scripting.FileSystemObject")

'SPECIFY THE PATH OF THE FOLDER IN WHICH SOURCE FILES RESIDE
Set oFolder1 = fso.GetFolder("c:\Template")

'COPY FILES TO USER PROFILES
sDocsAndSettings = "C:\Documents and Settings"  
Set colFolders = fso.GetFolder(sDocsAndSettings)

For Each oFolder In colFolders.SubFolders
Select Case LCase(oFolder.Name)
Case "admin", "administrator", "newuser", "all users", "default user.original", "localservice", "networkservice"
'LEAVE THE DEFAULT PROFILES ON THE MACHINE
Case Else
' Check for the path
If fso.FolderExists(sDocsAndSettings & oFolder.Name & "\Application Data") Then
'COPY FOLDER TO USER PROFILE
fso.CopyFolder oFolder1, sDocsAndSettings & oFolder.Name & "\Application Data\Microsoft\Templates" ,True
End If
End Select
Next

Set fso = Nothing
Set WSHShell = Nothing

0
Login to vote
EdT's picture

Grab a free download of the Windows Scripting Host (V5.6 or later) from the Microsoft site, and locate the Script56.chm help file that comes with it. Keep a link to it in your Quicklaunch bar as it is a most useful file, including code snippets for common functions in vbscript and jscript.

For checking and creating folders if absent, here is a code snippet that will give you an idea of what is required:

Dim fso, WshShell, WshSysEnv, user
Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
user = WshSysEnv("USERNAME")
if user = "" then user = "default"
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists("C:\Documents and Settings\"&user&"\Production") then fso.CreateFolder("C:\Documents and Settings\"&user&"\Production")

One thing to bear in mind is that the CreateFolder method does not create more than one directory "layer" at a time, so if you required another folder under Production, you would check for the Production folder first, and create it if necessary, then check for and create any required subfolder.

When it comes to copying files, I will paste an extract of the CopyFile method from the Script56.chm file, to give you an idea of what is available in the help file, and also to give you a chance to experiment with the code yourself.

CopyFile Method

Copies one or more files from one location to another.

	object.CopyFile ( source, destination[, overwrite] )

Arguments

object
Required. The object is always the name of a FileSystemObject.
source
Required. Character string file specification, which can include wildcard characters, for one or more files to be copied.
destination
Required. Character string destination where the file or files from source are to be copied. Wildcard characters are not allowed.
Optional. Boolean value that indicates if existing files are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite.
overwrite

Remarks

Wildcard characters can only be used in the last path component of the source argument. For example, you can use:

	[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile ("c:\\mydocuments\\letters\\*.doc", "c:\\tempfolder\\")
	[VBScript]
FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"

But you cannot use:

	[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile ("c:\\mydocuments\\*\\R1???97.xls", "c:\\tempfolder")
	[VBScript]
FileSystemObject.CopyFile "c:\mydocuments\*\R1???97.xls", "c:\tempfolder"

If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching files. Otherwise, destination is assumed to be the name of a file to create. In either case, three things can happen when an individual file is copied.

  • If destination does not exist, source gets copied. This is the usual case.
  • If destination is an existing file, an error occurs if overwrite is false. Otherwise, an attempt is made to copy source over the existing file.
  • If destination is a directory, an error occurs.

An error also occurs if a source using wildcard characters doesn't match any files. The CopyFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes made before an error occurs.

See Also

Copy Method | CopyFolder Method | CreateTextFile Method | DeleteFile Method | MoveFile Method

If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.

0
Login to vote
Steve_H45's picture

EDT:

Thanks for the information. It is a little advanced for me since I don't know much about VB.  know enough to sort my through it and understand what it is doing but not enough to incorporate it into what I have.   Starting from the above (very top of the forum) copy script can anyone incorporate the "If folder does not exist then create it, and copy the files". 

Also keeping with the same theme of the script just copy an individual file with a replace if exists option.  That could be a user input, or I can set it to Y or N in the script

I just dont know enough about incorporating it all together.  Thanks

0
Login to vote
QuietLeni's picture

Steve,

I am not exactly sure what you want to do. Are you trying to make a standard folder on each user's desktop that has an identical folder in it with files inside, or are you trying to make a folder somewhere else in each users' profile and put these files in there? I would like to know your objectives, because you may be able to achieve it in a much easier fashion.

I quite like putting things into the "All Users" profile if I want to put the same folder/files onto everyone's desktops, which is much easier.

Regards,

QuietLeni

What is the point of an Asset Management Solution that needs excessive management? Let me help you.

0
Login to vote
Steve_H45's picture

QuietLeni:  Thanks for helping out.

What I am trying to do is create a local folder in the users My Documents folder - call it "Production" then add files into it from the server. The above script works if the folder already exists but If the folder does not exist the script would create the folder, then copy the files.  There is only one user per machine (call it Test1) but the user accounts differ per machine( Test 1, Test2, Test3).  The above script eliminates the copying to unneeded profiles like Administrator, all Users, Sysadmin, etc so it works well.  I avoided using the "active user", or "Current logged on user" in the script due to the fact maybe nobody is logged on or maybe the administrator is logged in and the files would go to their account and not the Test1,2,3 profile.

I thought about using the "All users" profile but then I have scattered files on the mahcine that when we need to replace the machine we have to copy files from two location.

I would like to use the same script or theme to replace an individual file on the desktop of users.  They have shortcuts to servers/resources that will be moving and we just need to replace those shortcuts so they point to the new locations.  Same thing:  If file exists, replace but if it does not, just copy the file.

I hope that helps explain it
Steve

0
Login to vote
ahmed1111's picture

Hi,

mmm, I have created a script tocopy a folder from computer to all users profile

On error resume next
Dim WSHShell, filesys
Set WSHShell = WScript.CreateObject("WScript.Shell")
set filesys=CreateObject("Scripting.FileSystemObject")

' copies the uninstall script
filesys.Copyfolder "Rokdoc", "c:\Documents and Settings\%user%\" , TRUE

Set WSHShell = Nothing
WScript.Quit(0)

I'm very new, so you may see some silly staff in my script :(

I would like to copy folder from A location ( from network drive) to 25 computer, but I need to copy that folder to thier login ID profiles.

Can you help on that?

Cheers,

Ahmed

0
Login to vote
BigDaddyPS's picture

Now that ive been given a file to copy, how do I set up a task for this?  That is where I am having my issue.  How/where do I create the task and what are the steps.

0
Login to vote
ArcMap's picture

Hope its not too late for this reply.

Task Scheduler --> create new task --> configure TRIGGER according to your requirement.

0
Login to vote
Iskyfly's picture

Does anybody have a script that would do like the original script in this thread does, but for Windows 7?

 

I have an .ini file that I need to copy to;

users/[name]/appdata/roaming/imagenow folder (imagenow being the utilised application).

However I need it to go to all EXISTING user profiles. I know %appdata% references the CURRENT logged in user, so that won't work as I need to copy the file to each users appdating/roaming folder.

Anybody know how to go about doing this? I'm not well versed in vbscript.

 

Thank you!

0
Login to vote
QuietLeni's picture

Iskyfly,

Why not just run the policy once for each Logged-on user when the user logs on? That allows for permissions on the user profile.

What is the point of an Asset Management Solution that needs excessive management? Let me help you.

0
Login to vote