public static Boolean SetDirOwner(string dir, string Account)
{
DirectoryInfo dInfo = new DirectoryInfo(dir);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
IdentityReference User = new NTAccount(String.Format("{0}\\{1}",Environment.MachineName, Account));
try
{
dSecurity.SetOwner(User);
dInfo.SetAccessControl(dSecurity);
}
catch (Exception ex)
{
LibraryLogging.Error("SetDirOwner unable to SetOwner for {0} error {1}", dir, ex.Message);
return false;
}
return true;
}