Simple Script??

  • Thread starter Thread starter bddbrl
  • Start date Start date
B

bddbrl

I am trying to create a VBS script that will copy a file to all the profiles
on a
computer has anyone attempted this before that could assist me with this.
 
Well, it is not the most elegant solution I have ever written, but the script
below should do the trick.

Since you only needed to copy a file to every profile, I did not include
full directory recursion in the routine. Instead, the script will simply
look at all of the sub directories below "c:\documents and settings," and
will then assemble a destination path to use in the copy statement further
down in the routine.

In the section labeled "File Copy Information," you will need to provide a
template, of sorts, for the routine to use. Understand that the only thing
changing, as the routine runs, is the name of the directory during the copy;
the rest is information will be static. You will provide prefix and suffix
information for the routine to wrap around the directory name that it
discovers. You will also need to provide a path to the file you want to
copy, and justs it's name, as seen below. The routine, as it appears below,
will copy a file called File.txt to the Start folder in every profile.

Note that the statement below which looks at file attributes (22) is
included so that hidden system folders like "LocalService" and
"NetworkService" would be skipped during the copy routine. Also, the folder
"All Users" has been excluded because that is not actually a user profile,
either. All other folders found are assumed to be profiles.

Lastly, this forum tends to word-wrap sample code sometimes, so I am not
sure what what the code will look like when it is finally posted. =D Just
cut the code below, and paste it into notepad, and save it as a file name
such as PROFILECOPY.VBS. Double-click to run it. Unless there is an error,
this code will run silently.

I hope this helps!


' // Begin Script Here

Dim objFileCopy, fso, f
Dim strFilePath, strDestination, strDirLocation, strFileName

' // File Copy Information
strSourceDir="c:\documents and settings" ' // Prefix to path
strDestination="start menu\programs\startup" ' // suffix to path
strFilePath="c:\sample\file.txt" ' // File name with
path
strFileName="file.txt" ' // File name
alone

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(strSourceDir)
Set objFileCopy = objFSO.GetFile(strFilePath)

If f.subfolders.count > 0 Then
For Each folder In f.subFolders
if folder.attributes = 22 Then
' // Skip folders which are hidden
else
if folder.name="All Users" then
' // Skip the All Users Folder
else
' // Copy file using the assembled path plus file name
objFileCopy.Copy (folder+"\"+strDestination+"\"+strFileName)
end if
end if
next

end if

' // End Script Here

Vinson
 
Vinson this is really nice what you have here and I tested it exactly how you
have it scripted and it works great, however the only thing I would need to
change is the

FROM: strDestination="start menu\programs\startup" ' // suffix to path

TO: strDestination="start menu" ' // suffix to path

But when i run it the script fails. Am i doing something wrong?
 
Back
Top