码迷,mamicode.com
首页 > 其他好文 > 详细

文件夹锁定(Source)

时间:2014-12-16 19:03:34      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:http   io   sp   strong   on   文件   bs   ad   html   

文件夹锁定(Source)
private void Lock(string folderPath)
{
    try
    {
        string adminUserName = Environment.UserName;// getting your adminUserName
        DirectorySecurity ds = Directory.GetAccessControl(folderPath);
        FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);

        ds.AddAccessRule(fsa);
        Directory.SetAccessControl(folderPath, ds);
        MessageBox.Show("Locked");
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

private void UnLock(string folderPath)
{
    try
    {               
        string adminUserName = Environment.UserName;// getting your adminUserName
        DirectorySecurity ds = Directory.GetAccessControl(folderPath);
        FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);

        ds.RemoveAccessRule(fsa);
        Directory.SetAccessControl(folderPath, ds);
        MessageBox.Show("UnLocked");
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

文件夹锁定(Source)

标签:http   io   sp   strong   on   文件   bs   ad   html   

原文地址:http://www.cnblogs.com/dufu/p/4167682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!