Bonjour,

Je développe une appli en CSharp qui manipule l'Active Directory de Windows.
J'aimerai inclure du code MS-DOS dans mon code (afin de modifier les autorisations dans l'onglet "Sécurité" et "Partages" d'un répertoire).

Le problème... C'est que je n'y arrive pas. J'ai cherché sur le web. On m'a proposé une fonction du type affiché en dessous, mais quand je l'appelle, rien ne se passe (???). Je l'appelle pour executer une commande qui ressemble à ça:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
executeCommandSync("CACLS \\\\stquentin2\\Users\\"+extNom.ToLower()+"$"+" /T /G \"Administrateurs de l'entreprise\":C \"Admins du domaine\":C \"SOGESSUR\\"+extNom.ToLower()+"\":C");
Ca coince, alors je teste avec cette commande:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
executeCommandSync("echo bonjour");
Ca ne marche toujours pas...

J'utilise des fonctions dont je ne comprend pas le sens et dont je ne vois pas l'intérêt, mais is'agit d'une manipulation toute bête au fait...Quelqu'un aurait une idée ? Merci.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public void executeCommandSync(Object command)
        {
            try
            {
                // create the ProcessStartInfo using "cmd" as the program to be run,
                // and "/c " as the parameters.
                // Incidentally, /c tells cmd that we want it to execute the command that follows,
                // and then exit.
                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
                // The following commands are needed to redirect the standard output.
                // This means that it will be redirected to the Process.StandardOutput StreamReader.
                procStartInfo.RedirectStandardOutput = true;
                procStartInfo.UseShellExecute = false;
                // Do not create the black window.
                procStartInfo.CreateNoWindow = true;
                // Now we create a process, assign its ProcessStartInfo and start it
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo = procStartInfo;
                proc.Start();
                // Get the output into a string
                resultCMD = proc.StandardOutput.ReadToEnd();
                // Display the command output.
                //Console.WriteLine(result);
            }
            catch (Exception objException)
            {
                tbError.Text += objException.Message; 
            }
        }