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:
Set access type to 'Allow' to grant access to the user or 'Deny' to disallow access.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
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.
Pretty advanced and well explained. Good job on this PP.
/thanked

382
Looks good and yay for gexgens anti leech image idea![]()
Last edited by NextGen1; 08-13-2010 at 10:14 PM.
Added to tuts![]()
How to use this
Im such a noob at this![]()
/...
Write this sub-procedure:
And Call it as:
Where "E:\Michael Jackson\" is the folder I am applying permissions to.Code:WritePermissions("E:\Michael Jackson\", Environment.UserName, Security.AccessControl.FileSystemRights.Delete, Security.AccessControl.AccessControlType.Deny)
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.
.Celtics (08-15-2010)
What if i'm making the folder in full control?
And again, sorry for my nooby-ness!![]()