当前位置: 开源爱好者 » 编程教程 » C#教程 » 正文

C# 增加和移除指定文件的访问权限

C# 增加和移除指定文件的访问权限,显示特定的帮助文件内容以及索引项,文件访问权限这个是在2003环境 测试:

private void button12_Click(object sender, EventArgs e)
{//增加指定文件的访问权限:NTFS 2003环境测试           
    var MyFileName = "F:\\Northwind.mdb";
    var MyRight = System.Security.AccessControl.FileSystemRights.FullControl;
    var MyType = System.Security.AccessControl.AccessControlType.Allow;
    var MyAccount = "luobin\\Administrator";
    var MySecurity = System.IO.File.GetAccessControl(MyFileName);
    MySecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(MyAccount,MyRight, MyType));
    System.IO.File.SetAccessControl(MyFileName, MySecurity);
    MessageBox.Show("增加文件访问权限操作成功!", "信息提示", MessageBoxButtons.OK);           
}
private void button13_Click(object sender, EventArgs e)
{//移除指定文件的访问权限:NTFS 2003环境测试
   var MyFileName = "F:\\Northwind.mdb";
   var MyRight = System.Security.AccessControl.FileSystemRights.FullControl;
   var MyType = System.Security.AccessControl.AccessControlType.Allow;
   var MyAccount = "luobin\\Administrator";
   var MySecurity = System.IO.File.GetAccessControl(MyFileName);
   MySecurity.RemoveAccessRule(new System.Security.AccessControl.FileSystemAccessRule(MyAccount,MyRight, MyType));
   System.IO.File.SetAccessControl(MyFileName, MySecurity);
   MessageBox.Show("移除文件访问权限操作成功!", "信息提示", MessageBoxButtons.OK);          
}
private void button16_Click(object sender, EventArgs e)
{//显示特定的帮助文件内容
    var MyFileName = "C:\\Windows\\Help\\PINTLPAD.chm";
    Help.ShowHelp(this, MyFileName, HelpNavigator.TableOfContents);
}
private void button17_Click(object sender, EventArgs e)
{//显示指定帮助文件的索引
    var MyFileName = "C:\\Windows\\Help\\PINTLPAD.chm";
    Help.ShowHelpIndex(this, MyFileName);
}

CopyRight 2018© 开源爱好者 All Rights Reserved 豫ICP备16030607号 隐私声明 网站地图