Copy a File to All User Profile Directories on Target Computers

We recently received a request for help with using BatchPatch to copy a Microsoft Outlook signature file to the appropriate user profile directory on numerous target computers. BatchPatch already has a built-in function for copying files from the BatchPatch computer to a specified directory on target computers, but a problem arises when trying to copy a file to all user profile directories on target computers because the ‘copy file/folder’ function in BatchPatch requires you to enter a specific folder, by name. How then is the administrator able to copy a file to multiple user profile directories without knowing in advance which user profiles are on which computers?

The solution to the problem outlined above involves some custom scripting. There’s no way around it. However, with a very simple script, one can then use BatchPatch to deploy the script to all of the desired target computers, thereby enabling the copying of the desired file to all the desired target computers in the user profile folders on those computers.

In the particular question that we received the user needed to copy an Outlook signature file into each user profile directory — %userprofile%\AppData\Roaming\Microsoft\Signatures\. In order to do this we need to write a script that will first enumerate each of the user profile directories on the computer, and then will copy the desired file(s) into each user profile directory. Then use BatchPatch to deploy the script and the signature file to all of the desired target computers.

  1. Create a vbscript by pasting the following script text into a text document titled something like ‘script.vbs’. The .vbs file extension is required, but you may provide any name you desire for the file. The script below, when run on a computer, will check the registry to find out all of the user profile directories on the computer. It will then loop through and copy a file called “signature.file” from the folder that contains the script to each of the Outlook signatures folders on the computer. Note, we skip any profile directories that begin with ‘C:\Windows’ because we are interested in regular user profile directories that generally begin with C:\Users, so we have to discard the few that start with C:\Windows.

    On Error Resume Next
    Const HKEY_LOCAL_MACHINE = &H80000002
    strComputer = "."
    Set objRegistry=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
    objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
    For Each objSubkey In arrSubkeys
        strValueName = "ProfileImagePath"
        strSubPath = strKeyPath & "\" & objSubkey
        objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
    	Set fso = CreateObject("Scripting.FileSystemObject")
    	If InStr(Ucase(strValue),"C:\WINDOWS") = 0 Then
    	'	Wscript.Echo strValue & "\AppData\Roaming\Microsoft\Signatures\"
    		fso.CopyFile "signature.file", strValue & "\AppData\Roaming\Microsoft\Signatures\", True
    	End If
    Next
  2. Once we have the above script text saved to ‘script.vbs’ it’s actually very easy to deploy it with our signature.file. You’ll want to modify the script to substitute the actual name of your signature file for what I have just called ‘signature.file’ for the sake of this example.
  3. Put ‘script.vbs’ and ‘signature.file’ into a single folder on the BatchPatch computer. Make sure there is nothing else in that folder.
  4. Now you are ready to deploy the script using BatchPatch. In BatchPatch highlight the desired target computers in the grid. Then select ‘Actions > Deploy > Create/modify deployment’. In the deployment window you’ll select the file to deploy as the ‘script.vbs’. Then you’ll tick the box that says ‘Copy entire directory…’

  5. To begin the deployment, click on the ‘Execute’ button. When you do this BatchPatch will copy the folder containing the ‘script.vbs’ and ‘signature.file’ files to each selected target computer. BatchPatch will then execute the ‘script.vbs’ which will determine all of the user profile folders on each computer that it runs on, and it will copy the ‘signature.file’ file to each of the enumerated user profile folders.
This entry was posted in Blog, General, Tutorials and tagged , , . Bookmark the permalink. Both comments and trackbacks are currently closed.