+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Advances Folder Permission script in Coding and Web Development; I’m going through all of our kids folders one by one and changing the permissions, I’ve been having problems with ...
  1. #1
    alunmjones's Avatar
    Join Date
    Jul 2009
    Location
    North Wales
    Posts
    178
    Thank Post
    8
    Thanked 10 Times in 10 Posts
    Rep Power
    12

    Advances Folder Permission script

    I’m going through all of our kids folders one by one and changing the permissions, I’ve been having problems with something on the network changing the permissions on random student home folders to Everyone: delete and nothing else.

    I’m going through them and setting the Advanced Security settings for the folder manually, there has to be an easy way to set them. I did think about using Cacls or Xcacls as i have done in the past but after looking at it, it’s not granular enough for what I need, the settings are far to broad.

    Before I go and try and develop my own script or something to do it I thought I’d ask.

    ---- Things it should do ----

    Start at the top folder (Year Folder) and look down every folder contained within.
    Each Folder is a new Home folder of a new user
    Needs to look at the folder name and use it later
    Re-set the file permissions to inherit from above and remove the permissions currently set for the user
    (I have already made the changes to permissions the files inherit from the primary folder, that was easy)
    Set a new permission based on the folder name (this is where cacls/xcacls won’t work)
    The permission needs to be Allow everything except, Change Permissions and Take Ownership
    it should then propagate this down the home folder tree and move on to the next folder till it does not have any folders left.

    ---- ----

    Im not looking forward to doing it manually, i am thinking it will fix the problem im having.

    Can anyone point me in the right direction? I don’t know how to get vbscript to access the advanced file permissions, that’s really what i need help with, I think I can get it to do everything else, propagation might be a problem though

    Any help would be appreciated, thanks
    Last edited by alunmjones; 9th June 2011 at 11:19 AM.

  2. #2

    Join Date
    Nov 2011
    Location
    In the server room... cursing like a madman
    Posts
    32
    Thank Post
    11
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Does anyone have any scripts to do this? I am in desperate need for the same script.

  3. #3
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,219
    Thank Post
    216
    Thanked 226 Times in 195 Posts
    Rep Power
    73
    I have cobbled this together by ripping out parts of a script I have and altering bits. With some testing it should work.... I think :/ Copy and paste into notepad and save as a .vbs

    Code:
    '	Map a temporary network drive to year folder (root)
    
    Set objNetwork = CreateObject("WScript.Network") 
    objNetwork.MapNetworkDrive "Q:", "\\server\share\year"
    
    '	Dump the list of folder names into a CSV file for use later
    '	To do this open a command prompt and use DIR command
    
       intshort = 100
       strDump = "dir /b >c:\yearx.csv"
       objShell.Run "cmd"
       Wscript.Sleep intshort
       objShell.SendKeys strDump
       objShell.SendKeys "{ENTER}"
       Wscript.Sleep intshort
       objShell.SendKeys "exit"
       objShell.SendKeys "{ENTER}"
    
    '	Define a variable to use for the folder name
    
    Dim strFolderName
    
    '	Read the contents of newly created CSV into an array
    
    Const ForReading = 1
    
    Set objFSO = Nothing
    set objTextFile = Nothing
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile("C:\yearx.csv", ForReading)
    
    Do While objTextFile.AtEndOfStream <> True
    strNextLine = objTextFile.Readline
    arrUSERData = split(strNextLine, ",")
    
    strFolderName = arrUSERData(0)
    
    
    
    '	Use xcacls to set NTFS permissions
    '	This opens a command prompt and feeds the xcacls and variable into the line
    '	First command removes the old setting, second one creates the new one
    
       intshort = 100
       Set objShell = CreateObject("WScript.Shell")
       strPart1 = "xcacls q:\"
       strPart2 = " /R "
       strPart3 = " /T /E /C /G "
    
       objShell.Run "cmd"
       Wscript.Sleep intshort
    
       objShell.SendKeys strPart1 & strFolderName & strPart2 & strFolderName
       objShell.SendKeys "{ENTER}"
       objShell.SendKeys strPart1 & strFolderName & strPart3 & strFolderName
       objShell.SendKeys "{ENTER}"
       Wscript.Sleep intShort
    
    '	Clear the variable for the next pass through
    
       set strFolderName = Nothing
    
    Loop
    
    '	Close text file
    
    objTextFile.Close
    
    
    '	Remove the temporary network drive
    
       DriveLetter1 = "Q:"
       objNetwork.RemoveNetworkDrive Driveletter1, "True", "True"

  4. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,796
    Thank Post
    3,306
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365
    Quote Originally Posted by themightymrp View Post
    I have cobbled this together by ripping out parts of a script I have and altering bits. With some testing it should work.... I think :/ Copy and paste into notepad and save as a .vbs

    Code:
    '    Map a temporary network drive to year folder (root)
    
    Set objNetwork = CreateObject("WScript.Network") 
    objNetwork.MapNetworkDrive "Q:", "\\server\share\year"
    
    '    Dump the list of folder names into a CSV file for use later
    '    To do this open a command prompt and use DIR command
    
       intshort = 100
       strDump = "dir /b >c:\yearx.csv"
       objShell.Run "cmd"
       Wscript.Sleep intshort
       objShell.SendKeys strDump
       objShell.SendKeys "{ENTER}"
       Wscript.Sleep intshort
       objShell.SendKeys "exit"
       objShell.SendKeys "{ENTER}"
    
    '    Define a variable to use for the folder name
    
    Dim strFolderName
    
    '    Read the contents of newly created CSV into an array
    
    Const ForReading = 1
    
    Set objFSO = Nothing
    set objTextFile = Nothing
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile("C:\yearx.csv", ForReading)
    
    Do While objTextFile.AtEndOfStream <> True
    strNextLine = objTextFile.Readline
    arrUSERData = split(strNextLine, ",")
    
    strFolderName = arrUSERData(0)
    
    
    
    '    Use xcacls to set NTFS permissions
    '    This opens a command prompt and feeds the xcacls and variable into the line
    '    First command removes the old setting, second one creates the new one
    
       intshort = 100
       Set objShell = CreateObject("WScript.Shell")
       strPart1 = "xcacls q:\"
       strPart2 = " /R "
       strPart3 = " /T /E /C /G "
    
       objShell.Run "cmd"
       Wscript.Sleep intshort
    
       objShell.SendKeys strPart1 & strFolderName & strPart2 & strFolderName
       objShell.SendKeys "{ENTER}"
       objShell.SendKeys strPart1 & strFolderName & strPart3 & strFolderName
       objShell.SendKeys "{ENTER}"
       Wscript.Sleep intShort
    
    '    Clear the variable for the next pass through
    
       set strFolderName = Nothing
    
    Loop
    
    '    Close text file
    
    objTextFile.Close
    
    
    '    Remove the temporary network drive
    
       DriveLetter1 = "Q:"
       objNetwork.RemoveNetworkDrive Driveletter1, "True", "True"
    I would avoid using sendkeys where possible, if your email client or something else pops up half way through running said script it could get you into trouble

  5. #5
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,219
    Thank Post
    216
    Thanked 226 Times in 195 Posts
    Rep Power
    73
    Did you get this solved?

  6. #6

    Join Date
    Feb 2011
    Location
    Australia
    Posts
    109
    Thank Post
    0
    Thanked 10 Times in 10 Posts
    Rep Power
    9
    Have you tried icacls ?

SHARE:
+ Post New Thread

Similar Threads

  1. FileSystemObject Folder why permission denied
    By NetworkGeezer in forum Coding
    Replies: 16
    Last Post: 2nd September 2011, 05:10 PM
  2. folder permission problems
    By alunmjones in forum Mac
    Replies: 1
    Last Post: 8th June 2011, 02:44 PM
  3. Folder permission issues
    By bondbill2k2 in forum Windows Server 2000/2003
    Replies: 0
    Last Post: 27th May 2011, 02:27 PM
  4. Permission on a folder
    By Chuckster in forum Coding
    Replies: 1
    Last Post: 8th October 2009, 02:29 PM
  5. Replies: 15
    Last Post: 12th October 2006, 09:37 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •