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

Windows Forms Discussion :

Problème d'utilisation du Shell


Sujet :

Windows Forms

  1. #1
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Février 2008
    Messages
    33
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2008
    Messages : 33
    Par défaut Problème d'utilisation du Shell
    Bonjour,

    J'ai développé une application en VB.Net permettant de mettre à jour des fichiers. Pour cela, j'utilise du batch. Cependant, une erreur apparait lorsque je souhaite exécuter ma commande DOS :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    'lecture d'un fichier comprenant des nom de fichiers et copie de ceux-ci sur le bureau
    'Ce code est "validé" par les membre de la section DOS
    maCmd = "FOR /f ""delims=;"" %%i IN (C:\LesFichiersACopier.txt) DO copy ""%%i"" ""C:\Documents and Settings\USER\Bureau"""
    
    Shell(maCmd, AppWinStyle.MinimizedFocus, True)
    Erreur : Fichier introuvable

    Or mes fichiers existent bien et ont été vérifiés par l'instruction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    My.Computer.FileSystem.FileExists(lesFichiers)
    Merci de m'éclairer.

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    En fait, appeler Shell n'exécute pas une commande batch mais à démarrer un nouveau process, il faut donc que l'argument soit un fichier exécutable. La commande FOR est une commande batch, pas un exécutable. Donc il faut que tu appelles cmd.exe en mettant la commande en paramètre. Donc ton code devient :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    maCmd = "FOR /f ""delims=;"" %%i IN (C:\LesFichiersACopier.txt)
    DO copy ""%%i"" ""C:\Documents and Settings\USER\Bureau"""
    cmdExe = "c:\Windows\System32\cmd.exe"
    Shell(cmdExe + "/C """ + maCmd + """", AppWinStyle.MinimizedFocus, True)

  3. #3
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Février 2008
    Messages
    33
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2008
    Messages : 33
    Par défaut
    Merci pour ta réponse mais mon programme ne fonctionne toujours pas.

    Si j'effectue mon code Shell directement dans l'invite de commande, ça marche mais il y a toujours le même problème depuis visual studio :

    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
    30
    31
    32
     
    L'exception System.IO.FileNotFoundException n'a pas été gérée
      Message="Fichier introuvable."
      Source="Microsoft.VisualBasic"
      StackTrace:
           à Microsoft.VisualBasic.Interaction.Shell(String PathName, AppWinStyle Style, Boolean Wait, Int32 Timeout)
           à WindowsApplication2.Form1.Button1_Click(Object sender, EventArgs e) dans F:\Documents\Visual Studio 2005\Projects\WindowsApplication2\WindowsApplication2\Form1.vb:ligne 14
           à System.Windows.Forms.Control.OnClick(EventArgs e)
           à System.Windows.Forms.Button.OnClick(EventArgs e)
           à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
           à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           à System.Windows.Forms.Control.WndProc(Message& m)
           à System.Windows.Forms.ButtonBase.WndProc(Message& m)
           à System.Windows.Forms.Button.WndProc(Message& m)
           à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           à System.Windows.Forms.Application.Run(ApplicationContext context)
           à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           à WindowsApplication2.My.MyApplication.Main(String[] Args) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 81
           à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           à System.Threading.ThreadHelper.ThreadStart()

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    37
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 37
    Par défaut
    Bonjour,
    petite question toute bête (mais on ne sait jamais !),
    ton fichier cmd.exe se trouve-t-il bien sous c:\windows system32?, n'a-t-il pas été renommé ou déplacé?
    en tout cas, VS réagit comme s'il ne le trouvais pas,
    Bonne chance

  5. #5
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Février 2008
    Messages
    33
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2008
    Messages : 33
    Par défaut
    Oui, j'ai vérifié le chemin d'accès. De toute facon l'appli plante sur 2 PC différents...

    Un autre idée ?

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    37
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 37
    Par défaut
    Oui,
    dans le code que tomlev a cité essaie de rajouter un espace juste avant le /C
    ce qui donne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    maCmd = "FOR /f ""delims=;"" %%i IN (C:\LesFichiersACopier.txt)
    DO copy ""%%i"" ""C:\Documents and Settings\USER\Bureau"""
    cmdExe = "c:\Windows\System32\cmd.exe"
    Shell(cmdExe + " /C """ + maCmd + """", AppWinStyle.MinimizedFocus, True)
    car je crois que sans l'espace il comprend que le chemin de ton cmd est cmd.exe/C

    tiens moi au courant

  7. #7
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Février 2008
    Messages
    33
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2008
    Messages : 33
    Par défaut Problème résolu !
    Citation Envoyé par RomainDotNet Voir le message
    Oui,
    dans le code que tomlev a cité essaie de rajouter un espace juste avant le /C
    ce qui donne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    maCmd = "FOR /f ""delims=;"" %%i IN (C:\LesFichiersACopier.txt)
    DO copy ""%%i"" ""C:\Documents and Settings\USER\Bureau"""
    cmdExe = "c:\Windows\System32\cmd.exe"
    Shell(cmdExe + " /C """ + maCmd + """", AppWinStyle.MinimizedFocus, True)
    car je crois que sans l'espace il comprend que le chemin de ton cmd est cmd.exe/C

    tiens moi au courant
    Merci beaucoup, c'était donc ca le problème. Merci beaucoup.


  8. #8
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Citation Envoyé par RomainDotNet Voir le message
    dans le code que tomlev a cité essaie de rajouter un espace juste avant le /C
    Oups... bien vu

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2010] problème d'interraction et de loop entre vba et putty en utilisant wscript.shell
    Par legethi dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 03/11/2014, 22h42
  2. Réponses: 2
    Dernier message: 28/10/2010, 09h42
  3. Réponses: 7
    Dernier message: 18/07/2009, 01h28
  4. Réponses: 21
    Dernier message: 21/08/2008, 23h30

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