J'ai posté une question concernant la gestion de compte LDAP, mais après avoir exploré cela, ce n'est pas ce que je cherche. J'ai réussi à trouver deux façons de créer des utilisateurs sur une machine, et je trouve que l'un est beaucoup plus propre que l'autre, cependant, je ne sais pas comment convertir la première option à la deuxième option entièrement.Gestion de compte de machine locale ActiveDirectory - C#
Ce fut ma première solution:
Process MyProc = new Process();
MyProc.StartInfo.WorkingDirectory = System.Environment.SystemDirectory;
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyProc.StartInfo.Arguments = string.Format(@" user {0} {1} /ADD /ACTIVE:YES /EXPIRES:NEVER /FULLNAME:{0}"" /PASSWORDCHG:NO /PASSWORDREQ:YES", username, password);
MyProc.Start();
MyProc.WaitForExit();
int exit = MyProc.ExitCode;
MyProc.Close();
return exit == 0;
Et ce fut ma deuxième solution (preffered):
DirectoryEntry root = GetDELocalRoot();
DirectoryEntry user = root.Children.Add(username, "user");
//TODO: Always Active
//TODO: Never Expires
//TODO: No Password Change
//TODO: Password Required
user.Properties["description"].Value = "Account for running the MicaService and handling updates.";
user.Invoke("SetPassword", new object[] { password });
user.CommitChanges();
user.Close();
Je voudrais carte tous les paramètres de mon TODO: de la première solution dans ma deuxième solution plus soignée.
J'ont essayé la ligne suivante ainsi:
user.Properties["userAccountControl"].Value = ADS_USER_FLAG.ADS_UF_NORMAL_ACCOUNT | ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE | ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD;
Mais ceci ne fonctionne pas comme la propriété ne cache existe pas.
REMARQUE: le GetDELocalRoot() = renvoie new DirectoryEntry ("WinNT: //" + Environment.MachineName);
Merci pour toute contribution!
Cordialement
Tris