Usage

  • Download the script and save it to your desktop.
  • Add or amend the permissions you want to write.
  • Using Windows Explorer, navigate to the folder containing the users whose permissions you want to refresh.
  • Select the user folders you want to refresh (use CTRL and SHIFT to multi-select).
  • Drag and drop the selected folders onto the (desktop) script.

Download

Script

' Script to recreate folder permissions.
' by John Fermor
'
' Drag and drop folders onto the script to recreate the permissions
' specified below and also that of the folderuser name.
'
' Warning: No warantee implied. Use at your own risk!

Set objArgs = WScript.Arguments

if WScript.Arguments.Count = 0 then

msgbox "This script will replace the permissions of any folders that are dragged onto it." & vbCR & vbCR & "By default, it will add 'Administrators:F' and '%USERNAME%:C' permissions; " & vbCR & "other perms (Staff, Teachers, Managers, etc) can be added in the script." & vbCRLF & vbCRLF & "IMPORTANT: USE WITH CAUTION!" & vbCR & vbCR & "Usage: Drop 1 or more Home Folder(s) to the Script and wait for completion.", 16 ,"Reset HOME Folder Permissions Script v1.0.0"

else

' Initialise
' ----------
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")

' Set the DEFAULT Permissions of the Object Folder
' ------------------------------------------------
dim strPerms
strPerms = chr(34) & "Administrators" & chr(34) & ":F "
strPerms = strPerms & chr(34) & "Teachers" & chr(34) & ":R "

' Parse through EACH Folder, Setting DEFAULT Permissions (Above) + Folder (User) Name
' -----------------------------------------------------------------------------------
dim objFolder, RetVal
For I = 0 to objArgs.Count - 1
Set objFolder = fso.GetFolder(objArgs(I))

set wshShell = wscript.CreateObject("WScript.shell")
dim strCmd : strCmd = "%COMSPEC% /c Echo y|Cacls.exe " & chr(34) & objFolder.Path & chr(34) & " /T /C /G " & strPerms & chr(34) & objFolder.Name & chr(34) & ":C"

retVal = WSHShell.run(strCmd,0, true)
if retval > 0 then msgbox "Error setting permissions: " & objFolder.path, 0, "Error " & retVal

Next

' Clean Up
' --------
set objFolder = nothing
set wshShell = nothing
set fs = Nothing

' Complete!
' ---------
msgbox I & " User Folder(s) Processed", 64, "Complete!"

end if

Points to Note

You must wait for the message box to confirm the process has finished and it may take some time if you're updating a large number of users.

Use with caution! Test on a single user and check the outcome BEFORE you drag and drop multiple users folders onto the script.

The permissions can easily be changed by modifying the script. By default, it will add:
'%USERNAME%:C' (Change), Administrators:F (Full) and Teachers:R' (Read-only). Amend these as required.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *