I am writing a program which create some share folders on a 2012 server. I have a service account :
NTAccount serviceAccount = new NTAccount("myDomain", "SA_LiPAM");
This initialization work well.
if (folder.IndexOf('\\') == 0)
{
Directory.CreateDirectory("\\\\" + serveurName + "\\Test-Projects\\" + pPrjName.Text + folder);// Creation
fs = Directory.GetAccessControl("\\\\" + serveurName + "\\Test-Projects\\" + pPrjName.Text + folder);
fs.SetOwner(serviceAccount);// Set owner
Directory.SetAccessControl("\\\\" + serveurName + "\\Test-Projects\\" + pPrjName.Text + folde, fs);
}
On execution evrything seems ok, but, when I look on Security>advanced of the folder the owner is the localadmin...
Which way to definetly change the owner of this folder ?
Edit : I was using "File" instead of "Directory" thats why it doesn't work.