Copy a predefined file to a current user networked personal folder (VBS)

Purpose: You want to copy a predefined file to the currently logged on user personal network folder with SCCM

You might find yourself in a situation where some of the applications have been installed in one way and the others in another way. Depending on the problem, you might just want to clean the table and reinstall the the applications with your definitions. If this is not possible or would not be cost efficient, you could use SCCM to check if “something” exists and alter the workstations where this something is missing. In this example this “something” is a missing configuration file located in the personal network folder of an user.

Usage: cscript.exe IT_APP_VBS_CopyFileToNetworkedPersonalFolder.vbs
Configuration: You need to insert your own PREDEFINED FILE and LOCATION.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
' *********************************************************************************
' ** Script Name: IT_APP_VBS_CopyFileToNetworkedPersonalFolder
' ** Created on: 2.5.2013
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: To copy a predefined file to users networked personal folder (My Documents)
' ** Usage: IT_APP_VBS_CopyFileToNetworkedPersonalFolder (no parameters exist)
' **
' ** License: This program is free software: you can redistribute it and/or modify
' ** it under the terms of the GNU General Public License as published by
' ** the Free Software Foundation, either version 3 of the License, or
' ** (at your option) any later version.
' **
' ** This program is distributed in the hope that it will be useful,
' ** but WITHOUT ANY WARRANTY; without even the implied warranty of
' ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' ** GNU General Public License for more details.
' ** 
' ** History: 
' ** 1.0 / Jyri Lehtonen / 2.5.2013 / Initial version.
' *********************************************************************************
 
 function readFromRegistry (strRegistryKey, strDefault )
    Dim WSHShell, value
 
    On Error Resume Next
    Set WSHShell = CreateObject("WScript.Shell")
    value = WSHShell.RegRead( strRegistryKey )
 
    if err.number <> 0 then
        readFromRegistry= strDefault
    else
        readFromRegistry=value
    end if
 
    set WSHShell = nothing
end function
 
Set objFSO=CreateObject("Scripting.FileSystemObject")
strTargetDirectory = readfromRegistry("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal", "Personal")
strTargetDirectory = strTargetDirectory & "\YOUR_TARGET_DIR\"
'wscript.echo strTargetDirectory
 
strSourceFile = "C:\YOUR_SOURCE_DIR\YOUR_SOURCE.FILE"
objFSO.CopyFile strSourceFile, strTargetDirectory, true
' *********************************************************************************
' ** Script Name: IT_APP_VBS_CopyFileToNetworkedPersonalFolder
' ** Created on: 2.5.2013
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: To copy a predefined file to users networked personal folder (My Documents)
' ** Usage: IT_APP_VBS_CopyFileToNetworkedPersonalFolder (no parameters exist)
' **
' ** License: This program is free software: you can redistribute it and/or modify
' ** it under the terms of the GNU General Public License as published by
' ** the Free Software Foundation, either version 3 of the License, or
' ** (at your option) any later version.
' **
' ** This program is distributed in the hope that it will be useful,
' ** but WITHOUT ANY WARRANTY; without even the implied warranty of
' ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' ** GNU General Public License for more details.
' ** 
' ** History: 
' ** 1.0 / Jyri Lehtonen / 2.5.2013 / Initial version.
' *********************************************************************************

 function readFromRegistry (strRegistryKey, strDefault )
    Dim WSHShell, value

    On Error Resume Next
    Set WSHShell = CreateObject("WScript.Shell")
    value = WSHShell.RegRead( strRegistryKey )

    if err.number <> 0 then
        readFromRegistry= strDefault
    else
        readFromRegistry=value
    end if

    set WSHShell = nothing
end function

Set objFSO=CreateObject("Scripting.FileSystemObject")
strTargetDirectory = readfromRegistry("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal", "Personal")
strTargetDirectory = strTargetDirectory & "\YOUR_TARGET_DIR\"
'wscript.echo strTargetDirectory

strSourceFile = "C:\YOUR_SOURCE_DIR\YOUR_SOURCE.FILE"
objFSO.CopyFile strSourceFile, strTargetDirectory, true

Leave a Reply

Your email address will not be published. Required fields are marked *


seven − = three

Post Navigation