In the VBScript example below, I’m using the Icacls.exe utility to assign modify permissions to the D:\Test folder for the user Oliver on the LOOMER domain (or local machine). The script includes as comments some good resources on the subject.
' http://support.microsoft.com/kb/919240 ' http://technet.microsoft.com/en-us/magazine/2009.07.geekofalltrades.aspx ' http://timbolton.net/2010/06/23/icacls-changing-permissions-on-files-and-folders/ Dim strFolder, strUser, strDomain strFolder = "D:\Test" strUser = "Oliver" strDomain = "LOOMER" SetPermissions Function SetPermissions() Dim intRunError, objShell, objFSO Set objShell = CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists(strFolder) Then intRunError = objShell.Run("icacls " & strFolder & " /inheritance:r /grant:r " & strDomain &"\" & strUser & ":(OI)(CI)M ", 2, True) If intRunError <> 0 Then Wscript.Echo "Error assigning permissions for user " & strUser & " to folder " & strFolder End If Else Wscript.Echo "Error: folder " & strFolder & " does not exist" End If End Function
This script is a work-in-progress. To be considered complete, I want it to be able to create multiple directories and assign them permissions. For extra credit, I want it to be able to accept as input a list of usernames from a text file and iterate through them, creating folders where necessary and assigning them permissions.