+ Post New Thread
Results 1 to 8 of 8
Windows Thread, Mass setting NTFS permissions in Technical; I wasn't sure whether I should post this a seperate topic or not but I did in the end. I ...
  1. #1

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,333
    Thank Post
    525
    Thanked 2,596 Times in 2,014 Posts
    Blog Entries
    24
    Rep Power
    888

    Mass setting NTFS permissions

    I wasn't sure whether I should post this a seperate topic or not but I did in the end.

    I now have my server set up how I want. I have ~600 pupil folders which all have permissions set correctly except for the actual user/owner of the folder.

    The folders are named the same as the username.

    I am wondering if there is a quick way of changing the permissions on all the folders without having to go through each directory and add the user as a permitted user with their associated priviliges?

    Otherwise, I shall be here for a while editing each folder.

    Cheers
    Tony

  2. #2
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

    Re: Mass setting NTFS permissions

    I think this has been covered before but my internet is playing up so i cant really search on the forum for it. Anyway you can use a script to set the permissions using cacls and/or xcacls.

  3. #3

    Join Date
    Feb 2006
    Location
    Derbyshire
    Posts
    1,381
    Thank Post
    181
    Thanked 211 Times in 171 Posts
    Rep Power
    65

    Re: Mass setting NTFS permissions

    If you're happy enough on the command line, it should be a 2 minute job using CACLS and a FOR loop.

    for /D %I in (*) do cacls blah

    from a command prompt in the folder holding your pupil folders. The syntax for the cacls blah part will depend on exactly what you want to set...

    http://www.microsoft.com/resources/d...-us/cacls.mspx

    HTH

  4. #4

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,333
    Thank Post
    525
    Thanked 2,596 Times in 2,014 Posts
    Blog Entries
    24
    Rep Power
    888

    Re: Mass setting NTFS permissions

    Ah, I've done it using c# now. Cheers anyway. Would anyone like me to post the code I used?

  5. #5
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34

    Re: Mass setting NTFS permissions

    Very much so!

  6. #6

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,333
    Thank Post
    525
    Thanked 2,596 Times in 2,014 Posts
    Blog Entries
    24
    Rep Power
    888

    Re: Mass setting NTFS permissions

    Ok. Well here it is:

    Code:
                string user = "";
    
                string path = "";
    
                DirectoryInfo[] dirs = new DirectoryInfo(".").GetDirectories();
    
                foreach(DirectoryInfo di in dirs){
    
                    path = di.FullName;
    
                    user = di.Name;
    
                    try
    
                    {
    
                        DirectorySecurity dirSec = Directory.GetAccessControl(path);
    
                        dirSec.AddAccessRule(new FileSystemAccessRule(@"sch4290\" + user, FileSystemRights.FullControl, AccessControlType.Allow));
    
                        Directory.SetAccessControl(path, dirSec);
    
                        System.Console.WriteLine("DIR: " + user + " permissions added");
    
                    } catch(Exception e){
    
                        System.Console.WriteLine("Error: " + e.Message);
    
                    }
    
                }
    You need to use System.IO and System.Security.AccessControl for it to work.

    To prepare for this, I reset all permissions on the folders so that the groups that could access them were set up before these were set. I might tidy it up at some point and make it a little neater.

    It did the job though.

  7. #7

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,333
    Thank Post
    525
    Thanked 2,596 Times in 2,014 Posts
    Blog Entries
    24
    Rep Power
    888

    Re: Mass setting NTFS permissions

    Actually, it seems to have given the permissions to the top level but none of the files/folders within. I'll make a few changes and post the result here.

  8. #8

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,333
    Thank Post
    525
    Thanked 2,596 Times in 2,014 Posts
    Blog Entries
    24
    Rep Power
    888

    Re: Mass setting NTFS permissions

    Right, found the thing I needed to change.

    From this

    Code:
    dirSec.AddAccessRule(new FileSystemAccessRule(@"sch4290\" + user, FileSystemRights.FullControl, AccessControlType.Allow));
    to this

    Code:
    dirSec.AddAccessRule(new FileSystemAccessRule(@"sch4290\" + user, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
    And now it gives the right permissions to all child leaf objects and container objects.

    Oh, and remember - the share also has to have write permissions for the group which the users reside else all the files will come up as read only.



SHARE:
+ Post New Thread

Similar Threads

  1. GTK restrict drives and NTFS permissions
    By CyberNerd in forum Thin Client and Virtual Machines
    Replies: 2
    Last Post: 11th May 2007, 06:32 PM
  2. Replies: 4
    Last Post: 25th April 2007, 12:22 PM
  3. Replies: 4
    Last Post: 23rd November 2006, 10:33 PM
  4. Non-tech staff setting share permissions
    By ITWombat in forum How do you do....it?
    Replies: 26
    Last Post: 18th July 2006, 11:23 AM
  5. Replies: 4
    Last Post: 21st June 2006, 06:21 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
  •