Help needed with copying files to a users profile

BatchPatch Forums Home Forums BatchPatch Support Forum Help needed with copying files to a users profile

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #8785
    OHGroup
    Participant

    Hi, Can anyone help please.

    I have created a standard email signature that I need to deploy into C:UsersusernameAppDataRoamingMicrosoftSignatures on every computer. The difficulty lies with the variable username. I have tried multiple methods but all fail. Scripts and batch files execute perfectly on the client using %username% but fail to execute when run from BatchPatch. I am using elevated token and administrator accounts.

    Any advise would be greatly appreciated.

    Thanks

    Stewart

    #10034
    doug
    Moderator

    %username% works fine in BatchPatch remote command (logged output), but %username% doesn’t solve your problem because it will only echo the current user when using elevated token or the computer name when using SYSTEM. But the current user is going to be the admin account that you are using, not each/every user account on the computer. However, it sounds like your goal is to copy the email signature file to each user profile on each computer. To do this you would need to write a script that enumerates each user profile folder in C:Users, and then loops through that list to copy the file from the same directory as where the script resides to each profile folder on the same computer. Once you have a script like this working properly locally without using BatchPatch, then you could deploy the script plus the signature file using a BatchPatch deployment where you put both the script and the signature file in the same directory, and then you create the BatchPatch deployment with the “copy entire directory” box ticked. When the deployment runs it will copy the folder containing the script and the signature file to the target computer, and then it will run the script on the target computer which will copy the signature file from the script directory to each user profile directory. Just make sure that in your script you reference the signature file just by “signaturefile.whatever” without specifying an absolute path. This way no matter what the actual path is, so long as the signaturefile.whatever is in the same directory that the script runs from, the script will be able to find it when it executes the copy.

    #10035
    doug
    Moderator

    Copy the script text below to notepad and then save it as “script.vbs”

    On Error Resume Next
    Const HKEY_LOCAL_MACHINE = &H80000002
    strComputer = "."
    Set objRegistry=GetObject("winmgmts:\" & strComputer & "rootdefault:StdRegProv")
    strKeyPath = "SOFTWAREMicrosoftWindows NTCurrentVersionProfileList"
    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 & "AppDataRoamingMicrosoftSignatures"
    fso.CopyFile "signature.file", strValue & "AppDataRoamingMicrosoftSignatures", True
    End If
    Next

    #10036
    doug
    Moderator

    Then place script.vbs in a folder with your signature.file. Update the script to replace “signature.file” with whatever your actual signature file is named. So now you have the script.vbs along with your signature file in a folder on the BatchPatch computer. Next create a BatchPatch deployment to deploy the script.vbs. Tick the box that says “copy entire directory…” in the Deployment configuration. Then execute the deployment. If the Signatures folder does not already exist on the target computer this script will not automatically create it. The result is that all user profiles on the target computer that have the Signature folder will get a copy of the signature.file in that folder.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.