Reset the file permissions on homedrives

From Wiki

Revision as of 15:30, 23 June 2008 by SYNACK (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to:navigation, search

Creator: Ric Charlton

Script Type: VBS

This script can be used to recursively change all the file permissions within a folder containing homedrive folders.

There are a couple of provisos of course...

  1. The folders containing the homedrives must have the same name as the username of the owner
  2. XCACLS.vbs must exist (either in the path or within the same folder as the script)
    1. See http://support.microsoft.com/kb/825751 for information on XCACLS and where to get the latest version
  3. CHOWN.exe must also exist (again, either in the path or within the same folder as the script)
    1. Get CHOWN from http://wwwthep.physik.uni-mainz.de/~frink/chown/
  4. Make sure you understand what the script is doing as you may seriously stuff things up! You will also need to edit the script depending upon what exact permissions you want to apply

<vb> ' Script to change file permissions on homedrive folders ' Author: Adapted from Chris Hindmarch's code by Ric Charlton ' ------------------------------------------------------

Set FSO = CreateObject("Scripting.FileSystemObject") Set ObjShell = Wscript.CreateObject("Wscript.Shell")

ShowSubfolders FSO.GetFolder("v:\year 2006")

Sub ShowSubFolders(Folder)

   For Each Subfolder in Folder.SubFolders
       WScript.Echo "Folder = " & Subfolder

userName = SubFolder.Name CMDLine1 = "cscript xcacls.vbs """ & Subfolder & """ /F /S /T /G BAINES\staff:r ""Domain admins"":f BAINES\" & userName & ":m" WScript.Echo "Running XCACLS..." ObjShell.Run CMDLine1

CMDLine2 = "chown -r " & userName & " """ & Subfolder & "\*.*"""

WScript.Echo "Running CHOWN..." ObjShell.Run CMDLine2

   Next

End Sub </vb>