dufu

文件夹锁定(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);
    }
}

分类:

技术点:

相关文章:

  • 2021-11-30
  • 2022-02-05
  • 2021-12-17
  • 2021-09-27
  • 2021-04-21
  • 2021-09-03
  • 2021-11-29
  • 2022-02-19
猜你喜欢
  • 2021-08-05
  • 2021-08-23
  • 2021-11-02
  • 2021-09-27
  • 2021-08-11
相关资源
相似解决方案