// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Security.Principal; using System.Security.AccessControl; namespace E { public class MainClass { public static void Main(string[] args) { DirectoryInfo di = new DirectoryInfo(@"C:\z"); DirectorySecurity ds = di.GetAccessControl(AccessControlSections.Owner); ds.SetOwner(new NTAccount(WindowsIdentity.GetCurrent().Name)); di.SetAccessControl(ds); FileInfo fi = new FileInfo(@"C:\z.z"); FileSecurity fs = fi.GetAccessControl(AccessControlSections.Owner); fs.SetOwner(new NTAccount(WindowsIdentity.GetCurrent().Name)); fi.SetAccessControl(fs); } } }