Saqib Ullah

BootStrapper Know How

  Home  |   Contact  |   Syndication    |   Login
  109 Posts | 1 Stories | 820 Comments | 15 Trackbacks

News



Article Categories

Archives

Post Categories

Blogging websites

Favourite Blogs

Private Links

Sites

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.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Monday, May 28, 2007 7:47 PM

Feedback

# re: Apply Rights on File 1/15/2011 9:03 AM how to diagnose std symptoms
This is cool enough. Must read types.

# re: Apply Rights on File 12/18/2011 6:28 PM long prom dresses
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.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: