使用C#程序创建一个文本文件,以便在浏览器中打开文件时,它应该要求管理员权限(只有具有管理员权限的人才能打开该文件)。
static void Main(string[] args)
{
File.Create(@"E:\test.txt");
FileSecurity Security = File.GetAccessControl(@"E:\test.txt");
SecurityIdentifier Everybody = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
SecurityIdentifier Admin = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
Security.AddAccessRule(new FileSystemAccessRule(Everybody, FileSystemRights.FullControl, AccessControlType.Deny));
Security.AddAccessRule(new FileSystemAccessRule(Admin, FileSystemRights.FullControl, AccessControlType.Allow));
File.SetAccessControl(@"E:\test.txt", Security);
}