Results 1 to 8 of 8
  1. #1
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,139
    My Mood
    Dead

    [Tut]NTFS File Permissions[Tut]



    You all must be familiar with NTFS permissions in windows. In this tutorial I'll show you how to set NTFS permissions on files and folders via VB.NET.

    NTFS (NT File System) permissions are available to drives formatted with NTFS. The advantage with NTFS permissions is that they affect local users as well as network users and they are based on the permission granted to each individual user at the Windows logon, regardless of where the user is connecting.

    NTFS is the standard file system of Windows NT and all Windows operating systems that have come after it. Administrators can use the NTFS utility to provide access control for files and folders as a type of system security.

    Standard Windows NTFS permission dialog has a limitation. It can only set permissions on a single object at a time. I am using NTFS permissions for a while now and yesterday I wanted to lock many hundred files / folders. It is so annoying to set permissions 1 object at a time. So I quickly wrote a tool that write permissions on all objects by just a single click.

    Limitation of windows NTFS permissions Dialog:



    While it shows the security tab when a single file/folder is selected:



    The methods we will use are present in the 'Security' namespace.

    Let's start:

    ■ Create a new vb.net project.
    ■ Double click the form to open the code window.
    ■ Write the following sub-procedure in the code window:



    This is the method that will write permissions. The usage of this procedure is simple:

    [php]WritePermissions("E:\Michael Jackson\", Environment.UserName, Security.AccessControl.FileSystemRights.Delete, Security.AccessControl.AccessControlType.Deny)[/php]Explanation of sub-procedure:



    We define a rule using 'FileSystemAccessRule' method present in the AccessControl namespace. This rule inputs 3 parameters.

    1: Name of the user you want to set permissions on.
    2: Right(s) you want to deny or allow access on.
    3: Access Type that tells to allow or deny access on the right.

    The user can be anyone from the windows users.

    There is a vast range of 'Rights' you can apply:

    Code:
    Append Data
    Change Permissions
    Create Directories
    Create Files
    Delete
    Delete Sub-Directories and Files
    Execute File
    Full Control
    List Directory
    Modify
    Read
    Read and Execute
    Read Attributes
    Read Data
    Read Extended Attributes
    Read Permissions
    Synchronize
    Take Ownership
    Traverse
    Write
    Write Attributes
    Write Data
    Write Extended Attributes
    Set access type to 'Allow' to grant access to the user or 'Deny' to disallow access.



    We use the 'Directory Security' class to add the rule we just created. The rule itself is nothing so this will bind the directory / file to that rule.



    Simply call the 'AddAccessRule' method and input the rule.



    Finally, set the access control on the particular file / folder using 'My.Computer.Filesystem' namespace. Pretty simple.

    Now simply use the For Each loop to set permissions on multiple file / folders:



    You can use NTFS permissions to take ownership and deny access on your important files of your software. There are many more usages of NTFS. It's upto you on how to use it.

  2. The Following 5 Users Say Thank You to Hassan For This Useful Post:

    .Celtics (08-13-2010),Blubb1337 (08-13-2010),Jason (08-13-2010),Lolland (08-14-2010),NextGen1 (08-13-2010)

  3. #2
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,109
    Pretty advanced and well explained. Good job on this PP.

    /thanked



  4. #3
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Looks good and yay for gexgens anti leech image idea
    Last edited by NextGen1; 08-13-2010 at 10:14 PM.

  5. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,139
    My Mood
    Dead
    Quote Originally Posted by NextGen1 View Post
    Looks good and yay for gexgens anti leech image idea
    Ya, it looks good.
    And lol yea its a good idea for stopping leechers !!

  6. #5
    Lolland's Avatar
    Join Date
    Feb 2009
    Gender
    male
    Location
    Lolland!
    Posts
    3,156
    Reputation
    49
    Thanks
    868
    My Mood
    Inspired
    Added to tuts

  7. The Following 2 Users Say Thank You to Lolland For This Useful Post:

    Blubb1337 (08-14-2010),Hassan (08-14-2010)

  8. #6
    .Celtics's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    148
    Reputation
    10
    Thanks
    5
    My Mood
    Crappy
    How to use this
    Im such a noob at this

  9. #7
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,139
    My Mood
    Dead
    Quote Originally Posted by .Celtics View Post
    How to use this
    Im such a noob at this
    / ...

    Write this sub-procedure:



    And Call it as:

    Code:
       WritePermissions("E:\Michael Jackson\", Environment.UserName, Security.AccessControl.FileSystemRights.Delete, Security.AccessControl.AccessControlType.Deny)
    Where "E:\Michael Jackson\" is the folder I am applying permissions to.
    Environment.Username is the name of the currently logged in windows user.
    Where "Security.AccessControl.FileSystemRights.Delete" is the right. This operation will be allowed on the basis of the next parameter.
    "Security.AccessControl.AccessControlType.Deny" tells the AccessControl class to deny permission of deleting on the folder "Michael Jackson". It applies on the currently logged-in user only.

  10. The Following User Says Thank You to Hassan For This Useful Post:

    .Celtics (08-15-2010)

  11. #8
    .Celtics's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    148
    Reputation
    10
    Thanks
    5
    My Mood
    Crappy
    What if i'm making the folder in full control?

    And again, sorry for my nooby-ness!

Similar Threads

  1. [TuT] a very easy way to delete files for noobs.
    By XGelite in forum Visual Basic Programming
    Replies: 11
    Last Post: 11-02-2009, 05:24 PM
  2. [Request] Tut on .ini Files?
    By FatCat00 in forum Visual Basic Programming
    Replies: 4
    Last Post: 10-24-2009, 05:33 AM
  3. [TuT] How to delete read only files.
    By XGelite in forum Visual Basic Programming
    Replies: 0
    Last Post: 10-13-2009, 09:59 AM
  4. [Tut] How To Fix The TNT Hack Permission Problem \ With Pictures.
    By luckyy23 in forum Combat Arms Hacks & Cheats
    Replies: 20
    Last Post: 08-23-2009, 11:33 AM

Tags for this Thread