本文介绍了如何拒绝删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助我.
我曾用此代码拒绝对文件进行删除操作.但不适用于管理员帐户.
它只能使用受限的用户帐户(例如无法完全控制的来宾帐户/计算机帐户).
请帮我.
我想在删除一个文件时拒绝对管理员帐户和受限用户帐户的删除操作.
please help me.
this code i used to deny delete operation on a file . but it is not working for administrator Account.
its working with limited user account(for example guest account/compuetr account which doesnt have full control) .
plz help me.
i want to deny delete operation for administrator account and limited user account when some one delete file .
private void button1_Click(object sender, EventArgs e)
{
string fileName = @"E:\kkk.txt";
WindowsIdentity ident = WindowsIdentity.GetCurrent();
WindowsPrincipal user = new WindowsPrincipal(ident);
AddFileSecurity(fileName, user.Identity.Name,
FileSystemRights.Delete, AccessControlType.Deny);
}
public static void AddFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{
FileSecurity fSecurity = File.GetAccessControl(fileName);
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
rights, controlType));
File.SetAccessControl(fileName, fSecurity);
}
推荐答案
File.SetAttributes(fileName, FileAttributes.ReadOnly);
我认为这对您有帮助
i think this will help you
这篇关于如何拒绝删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!