Copy a predefined file to all local user profiles (VBS)

Purpose: You want to copy a predefined file to all local workstation user profiles 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 needed in EVERY USER PROFILE of the workstation.

Usage: cscript.exe IT_APP_VBS_CopyFileToEveryUserProfile.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
46
' *********************************************************************************
' ** Script Name: IT_APP_VBS_CopyFileToEveryUserProfile
' ** Created on: 30.10.2012
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: To copy a predefined file to all local workstation user profiles
' ** Usage: IT_APP_VBS_CopyFileToEveryUserProfile (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 / 30.10.2012 / Initial version.
' ** 1.1 / Jyri Lehtonen / 2.5.2013 / Created better configuration options.
' *********************************************************************************
 
strCopyFileName = PATH_TO_YOUR_FILE
 
'********************************************************************************************
'******** COPY A file from c:\TEMP\ to TO EVERY USER IN THE c:\Users\ FOLDER ****************
'********************************************************************************************
Set oWshell = CreateObject("WScript.Shell")
Set oFileSystem = CreateObject("Scripting.FileSystemObject")
Set strUsersFolder = oFileSystem.GetFolder("C:\Users\")
Set strSubFolders = strUsersFolder.SubFolders
    
For Each subfolder in strSubFolders
    if subfolder.name = "All Users" or subfolder.name = "Default" or subfolder.name = "Default User" or subfolder.name = "Public" or subfolder.name = strCurrentUserName Then
        'MsgBox(subfolder.name & " THIS FOLDER IS PROTECTED")
        Else :  'msgbox(subfolder.name & " We will copy to this folder")
                strFolderPath = "c:\Users\" & subfolder.name & "\Documents\YOUR_TARGET_DIR\"
                folderCopyCommand = "%comspec% /C xcopy /Y " & chr(34) & strCopyFileName & chr(34) & " " & chr(34) & strFolderPath & chr(34)
                oWshell.Run folderCopyCommand, 0, True
    End if
        
    'strLoopFolders = strLoopFolders & subfolder.name
    'strLoopFolders = strLoopFolders & vbCrLf
Next
'MsgBox(strLoopFolders)
' *********************************************************************************
' ** Script Name: IT_APP_VBS_CopyFileToEveryUserProfile
' ** Created on: 30.10.2012
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: To copy a predefined file to all local workstation user profiles
' ** Usage: IT_APP_VBS_CopyFileToEveryUserProfile (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 / 30.10.2012 / Initial version.
' ** 1.1 / Jyri Lehtonen / 2.5.2013 / Created better configuration options.
' *********************************************************************************

strCopyFileName = PATH_TO_YOUR_FILE

'********************************************************************************************
'******** COPY A file from c:\TEMP\ to TO EVERY USER IN THE c:\Users\ FOLDER ****************
'********************************************************************************************
Set oWshell = CreateObject("WScript.Shell")
Set oFileSystem = CreateObject("Scripting.FileSystemObject")
Set strUsersFolder = oFileSystem.GetFolder("C:\Users\")
Set strSubFolders = strUsersFolder.SubFolders
	
For Each subfolder in strSubFolders
	if subfolder.name = "All Users" or subfolder.name = "Default" or subfolder.name = "Default User" or subfolder.name = "Public" or subfolder.name = strCurrentUserName Then
		'MsgBox(subfolder.name & " THIS FOLDER IS PROTECTED")
		Else : 	'msgbox(subfolder.name & " We will copy to this folder")
				strFolderPath = "c:\Users\" & subfolder.name & "\Documents\YOUR_TARGET_DIR\"
				folderCopyCommand = "%comspec% /C xcopy /Y " & chr(34) & strCopyFileName & chr(34) & " " & chr(34) & strFolderPath & chr(34)
				oWshell.Run folderCopyCommand, 0, True
	End if
		
	'strLoopFolders = strLoopFolders & subfolder.name
	'strLoopFolders = strLoopFolders & vbCrLf
Next
'MsgBox(strLoopFolders)

Leave a Reply

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


+ two = eleven

Post Navigation