Geeks With Blogs
Saqib Ullah BootStrapper Know How
This following code create a file and give right only to the "localAdmin" user in my case “localAdmin” is administrator. Next time if you login from guest account and try to access the same file so you will get error message of access deined because user not have the rights.

using System;
using System.IO;
using System.Data;
using System.ComponentModel;
using System.Security.AccessControl;
using System.Security.Principal;
 
namespace Permission
{
    public partial class CreatePermissoinFile
    {
        ///<summary>
        /// Create File function
        ///</summary>
        ///<param name="fileName">Name of file</param>
        public void CreateFile(string fileName)
        {
            //localAdmin user has Administrator priviliges
            NTAccount user = new NTAccount("localAdmin");
            FileSystemAccessRule ar = new FileSystemAccessRule(user, FileSystemRights.FullControl, AccessControlType.Allow);
            FileSecurity fs = new FileSecurity();
            fs.AddAccessRule(ar);
            //Name of the File with extension
            //like: test.doc
            System.IO.File.Create(fileName, 1000, FileOptions.None, fs);
        }
    }
}

Working
Call CreatePermissionFile class and login from non-administrative account into your computer. Open created file and you will get “Access is denied” error.
 
Reason
Because login user is non-administrative and doesn’t have right to open and move.
Posted on Monday, May 28, 2007 7:47 PM .Net , Security | Back to top


Comments on this post: Apply Rights on File

# re: Apply Rights on File
Requesting Gravatar...
This is cool enough. Must read types.
Left by how to diagnose std symptoms on Jan 15, 2011 9:03 AM

# re: Apply Rights on File
Requesting Gravatar...
Even a straightforward white or an off white dress will frequently operate nicely to get a wedding celebration and goes easy on your pocket. It's simple to get low-cost dresses once you locate shops that market wholesale bridesmaids dresses.
Left by long prom dresses on Dec 18, 2011 6:28 PM

Your comment:
 (will show your gravatar)


Copyright © Saqib Ullah | Powered by: GeeksWithBlogs.net