IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Commandes MS-DOS sous C-SHARP


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Inscrit en
    Mai 2011
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mai 2011
    Messages : 10
    Par défaut Commandes MS-DOS sous C-SHARP
    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; 
                }
            }

  2. #2
    Membre éclairé Avatar de Faereth
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    92
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2007
    Messages : 92
    Par défaut
    Bonjour, j'ai eu le même problème il y a quelques semaines.


    J'ai résolu comme ceci :


    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
    private void executeCommandSync(Object sender)
    {
       try
      {
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.CreateNoWindow = true;
        psi.UseShellExecute = false;
        
        psi.FileName = "cmd";
        psi.Arguments = "start /c" + command; //Attention au format de command
      
        Process.start(psi);
      }
      catch
      {
        tbError.Text += objException.Message;
      }
    }
    Voilà en espérant t'aider.

Discussions similaires

  1. [PowerBuilder] Executer une commande DOS sous PB
    Par Deedoo2000 dans le forum Powerbuilder
    Réponses: 3
    Dernier message: 09/08/2006, 15h54
  2. commandes en parallèle sous MS DOS ?
    Par djnellio dans le forum Autres Logiciels
    Réponses: 2
    Dernier message: 15/06/2006, 09h08
  3. commande dos sous java
    Par yann999 dans le forum API standards et tierces
    Réponses: 6
    Dernier message: 12/05/2006, 14h18
  4. faire tourner une commande dos sous application java
    Par Terminator dans le forum API standards et tierces
    Réponses: 22
    Dernier message: 02/05/2006, 22h33
  5. commande dos sous oracle
    Par tcy dans le forum Oracle
    Réponses: 4
    Dernier message: 18/07/2005, 11h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo