string filepath = @"C:\Program Files (x86)\Internet Explorer\iexplore.exe"; //Get Currently Applied Access Control FileSecurity fileS = File.GetAccessControl(filepath); //Update it, Grant Current User Full Control SecurityIdentifier cu = WindowsIdentity.GetCurrent().User; fileS.SetOwner(cu); fileS.SetAccessRule(new FileSystemAccessRule(cu, FileSystemRights.FullControl, AccessControlType.Allow)); //Update the Access Control on the File File.SetAccessControl(filepath, fileS); //Delete the file File.Delete(filepath);
Add the following importers
using System.IO; using System.Security.AccessControl; using System.Security.Principal;
Run the code in elevated mode.
Josy Nov 06 '13 at 16:12 2013-11-06 16:12
source share