yogi sharma

yogi sharma

  • NA
  • 2
  • 3.7k

How to make Antivirus software using c# ? scan all file

Jan 8 2019 7:09 AM
How to make Antivirus software using c# ? scan all file in drive. when i try to get scan file from c drive it showerror that Unauthorised access. How to resolve. I used this code but its not working.
 
private void SetAccessRights(string file)
{
FileSecurity fileSecurity = File.GetAccessControl(file);
// DirectorySecurity fileSecurity = Directory.GetAccessControl(file);
AuthorizationRuleCollection rules = fileSecurity.GetAccessRules(true, true, typeof(NTAccount));
foreach (FileSystemAccessRule rule in rules)
{
string name = rule.IdentityReference.Value;
if (rule.FileSystemRights != FileSystemRights.FullControl)
{
FileSecurity newFileSecurity = File.GetAccessControl(file);
FileSystemAccessRule newRule = new FileSystemAccessRule(name, FileSystemRights.FullControl, AccessControlType.Allow);
newFileSecurity.AddAccessRule(newRule);
File.SetAccessControl(file, newFileSecurity);
}
}
}
 

Answers (1)