Description:
This post describes how to delete a file from multiple user profiles (normal.dot in this example). Also has the ability to exclude certain profile folders. Could be easily combined with this script to delete folders/subdolfers and files from each profile: Delete a Folder and its Subfolders
Source:
Script:
' Sample VB Script to remove a designated file (default is NORMAL.DOT) located in the profile folder for every user on the
' system. There is provision for exempting certain folders via the constant ProtectedUsers which is set to a comma separated
' list which can be altered according to your requirements
'
' You should alter constant DeleteProtectedUsers from FALSE to TRUE to delete *ALL* copies of the file regardless of profile
'
Const FileToDelete = "Normal.DOT"
Const AllUsers = "\All Users"
Const DeleteProtectedUsers = "FALSE"
Const TemplatesFolder = "Application Data\Microsoft\Templates"
Const ProtectedUsers = "Default User,Administrator,All Users,NetworkService,LocalService"
Dim oFSO, oWSH
Dim sAllUsersProfile, oAllUsersFolder, sProfilesRoot, oFolder
Dim colFSOSubFolders
Dim protuserarray
Dim DeleteFlag
On Error Resume Next ' this is set because the designated file may be locked from deletion
protuserarray = Split(ProtectedUsers,",")
' Instantiate the objects
Set oFSO = CreateObject("Scripting.FileSystemObject")
set oWSH = CreateObject("WScript.Shell")
' Get the Allusers profile folder path first and from this determine profiles parent folder
'
sAllUsersProfile = oWSH.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
Set oAllUsersFolder = oFSO.GetFolder(sAllUsersProfile)
sProfilesRoot = oAllUsersFOlder.ParentFolder
' Now enumerate all existing user profile folders
Set oFolder = oFSO.GetFolder(sProfilesRoot)
Set colFSOSubfolders = oFolder.Subfolders
' Now go through each existing user profile folder looking for the designated file to delete
For Each objSubfolder in colFSOSubfolders
DeleteFlag = "TRUE"
if oFSO.FileExists(sProfilesRoot & "\" & objSubfolder.Name & "\" & TemplatesFolder & "\" & FileToDelete) then
' Found the file, now establish whether containing folder is on the exempt list
if NOT DeleteProtectedUsers then
For Each element in protuserarray
if ucase(element) = ucase(objSubfolder.Name) then
DeleteFlag = "FALSE" ' mark this occurrence of the designated file as exempt from deletion
exit for
end if
Next
end if
If DeleteFlag then
' File was found in a folder that is not exempt, so go ahead and attempt to delete
oFSO.DeleteFile sProfilesRoot & "\" & objSubfolder.Name & "\" & TemplatesFolder & "\" & FileToDelete,TRUE
end if
end if
Next
' Clean up before exiting
set oFSO = Nothing
set oWSH = Nothing