Право доступу - система

// Запустити програму від імені система, напр. через планувальник завдань

// Встановлює права доступу на папку 1 - систама

string pathIntern = @"C:\1";

DirectoryInfo diIntern = new DirectoryInfo(pathIntern);

DirectorySecurity dsecIntern = diIntern.GetAccessControl();

SecurityIdentifier s = new SecurityIdentifier("S-1-5-18");

string username = s.Translate(typeof(NTAccount)).Value;

IdentityReference newUser = new NTAccount(username);

dsecIntern.SetOwner(newUser);

//FileSystemAccessRule permissions = new FileSystemAccessRule(newUser, FileSystemRights.FullControl, AccessControlType.Allow);

// dsecIntern.AddAccessRule(permissions);

diIntern.SetAccessControl(dsecIntern);