Updated code using ICACLS instead of XCACLS.
previous post: http://nusak.blogspot.com/2009/09/reset-home-folder-permissions-for.html
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 = "F"
'================================CODE=========================================
IF objFSO.FolderExists(strFolder) THEN
FOR Each Folder In SubFolders
strUser = replace(Lcase(Folder),strFolder,"")
commando = "icacls """ &Folder &""" /grant ""System"":F ""Creator Owner"":F ""Domain Admins"":" &UsrPerm1 _
&" """ &Domain &strUser &""":F /T /C"
iReturn = objShell.Run("%comspec% /K" & commando)
Counter = Counter + 1
' This sleep is specially done to not overload the system with
' xcacls screens.
wscript.echo commando
wscript.sleep 6000
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
No comments:
Post a Comment