Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const string FILE = @"C:test.txt";
- var fs = File.GetAccessControl(FILE);
- var sid = fs.GetOwner(typeof(SecurityIdentifier));
- Console.WriteLine(sid); // SID
- var ntAccount = sid.Translate(typeof(NTAccount));
- Console.WriteLine(ntAccount); // DOMAINusername
- var ntAccount = new NTAccount("DOMAIN", "username");
- fs.SetOWner(ntAccount);
- try {
- File.SetAccessControl(FILE, fs);
- } catch (InvalidOperationException ex) {
- Console.WriteLine("You cannot assign ownership to that user." +
- "Either you don't have TakeOwnership permissions, or it is not your user account."
- );
- throw;
- }
- File.GetAccessControl(fileName).GetOwner().ToString()
Add Comment
Please, Sign In to add comment