Sunday, September 27, 2009

Reset home folder permissions for multiple users

http://wasteil.blogspot.com/2007/04/reset-permissions-home-folder.html


'============================================================================
' VBScript Source File
' NAME: Permissions Home Folder
' AUTHOR: Ruudvdh (WASTEIL)
' WEBSITE : http://wasteil.blogspot.com
' DATE : 19-3-2007
' COMMENT: This script changes the permissions of all the subfolders in the
' specified folders. It uses the folder name and matches this with a username
' in Active Directory. Therefore the foldername must be equal to the username.
'
' Permissions (See CONST UsrPerm1 & UsrPerm2:
' R = Read
' C = Change (write)
' F = Full control
' P = Change Permissions (Special access)
' O = Take Ownership (Special access)
' X = EXecute (Special access)
' E = REad (Special access)
' W = Write (Special access)
' D = Delete (Special access)
'
' !!!NEEDED PROGRAMS!!!
' XCACLS.EXE
' This program is part of the Support Tools
' DOWNLOAD:
' http://support.microsoft.com/kb/892777
'
'============================================================================

' DECLARING VARIABLES
Option Explicit
DIM Commando, Counter, Domain
DIM Folder, iReturn, objFSO
DIM objShell, objSysInfo, rootFolder
DIM strFolder, strUser, SubFolders

' INSTANTIATING AN OBJECT PART1
SET objSysInfo = CreateObject("ADSystemInfo")
SET objFSO = CreateObject("Scripting.FileSystemObject")
SET objShell = wscript.createObject("wscript.shell")

' ASSIGNING VALUES TO VARIABLES
strFolder = Lcase(Inputbox(Ucase("Enter path Home folder") &VbCr &VbCr _
&"Use the following syntax:" &VbCr _
&"D:\Users\","Home-Folder","D:\Users\"))
Domain = objSysInfo.ForestDNSName & "\"

' INSTANTIATING AN OBJECT PART2
SET rootFolder = objFSO.GetFolder(strFolder)
SET SubFolders = rootFolder.SubFolders

' ASSIGNING VALUES TO CONSTANTS
' INFO: You can find the possible permissions in the comment
CONST Usr1 = "Domain Admins"
CONST UsrPerm1 = "F"
CONST UsrPerm2 = "RWC"

'================================CODE=========================================

IF objFSO.FolderExists(strFolder) THEN
FOR Each Folder In SubFolders
strUser = replace(Lcase(Folder),strFolder,"")
commando = "xcacls " &Folder &" /g ""Domain Admins"":" &UsrPerm1 _
&" """ &Domain &strUser &""":" &UsrPerm2 &" /T /C /Y"
iReturn = objShell.Run(commando)
Counter = Counter + 1
' This sleep is specially done to not overload the system with
' xcacls screens.
wscript.sleep 1500
NEXT
wscript.echo "Finished!" &VBCR &Counter &" folders are reset."
ELSE
wscript.Echo "Folder: " &Ucase(strFolder) &" doesn't exist." &VbCr _
&"Verify the location and try again."
END IF

SET objSysInfo = NOTHING
SET objFSO = NOTHING
SET objShell = NOTHING
SET rootFolder = NOTHING
SET SubFolders = NOTHING
'=============================END=OF=CODE=====================================
wscript.quit



For error checking of the subfolder loop, I put in iReturn = objShell.Run("%comspec% /K" & commando) to see the
individual CMD screens.

No comments: