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 Presentation Foundation Discussion :

Envoie d'un ping


Sujet :

Windows Presentation Foundation

  1. #21
    Invité
    Invité(e)
    Par défaut
    Bon, j'espère que tu auras du temps pour savoir comment convertir du C# vers du VB.Net :
    Code C# : 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
    33
    34
    35
    36
    37
    38
    39
    40
     
    public partial class MainWindow : Window
    {
    	private string OutputOrErrorMessage = string.Empty;
    	public MainWindow()
    	{
    		InitializeComponent();
    	}
     
    	private void Button_Click(object sender, RoutedEventArgs e)
    	{
                    this.ping = new Process();
    		this.ping.ErrorDataReceived += pingOutputOrErrorDataReceived;
    		this.ping.OutputDataReceived += pingOutputOrErrorDataReceived;
     
    		this.ping.StartInfo.FileName = "ping.exe";
    		this.ping.StartInfo.Arguments = "www.google.com";
    		this.ping.StartInfo.CreateNoWindow = true;
    		this.ping.StartInfo.UseShellExecute = false;
    		this.ping.StartInfo.RedirectStandardError = true;
    		this.ping.StartInfo.RedirectStandardOutput = true;
    		this.ping.StartInfo.StandardErrorEncoding = Encoding.ASCII;
    		this.ping.StartInfo.StandardOutputEncoding = Encoding.ASCII;
     
    		this.ping.Start();
    		this.ping.BeginErrorReadLine();
    		this.ping.BeginOutputReadLine();
    		this.ping.WaitForExit();
     
    		this.ping.ErrorDataReceived -= pingOutputOrErrorDataReceived;
    		this.ping.OutputDataReceived -= pingOutputOrErrorDataReceived;
     
    		MessageBox.Show(this.OutputOrErrorMessage);
    	}
     
    	private void pingOutputOrErrorDataReceived(object sender, DataReceivedEventArgs e)
    	{
    		this.OutputOrErrorMessage += e.Data + Environment.NewLine;
    	}
    }

  2. #22
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 63
    Points : 30
    Points
    30
    Par défaut
    Merci, ça me donne ça :

    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
        Dim ping As System.Diagnostics.Process = New System.Diagnostics.Process()
        Dim OutputMessage As String = New String("")
     
        'Bouton qui permet l'envoie d'un ping vers www.google.com
        Private Sub BT_PING_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BT_PING.Click
            ping = New Process()
            ping.OutputDataReceived += pingOutputDataReceived
            ping.StartInfo.FileName = "ping.exe"
            ping.StartInfo.Arguments = "www.google.com"
            ping.StartInfo.CreateNoWindow = True
            ping.StartInfo.UseShellExecute = False
            ping.StartInfo.RedirectStandardError = True
            ping.StartInfo.RedirectStandardOutput = True
            ping.StartInfo.StandardErrorEncoding = System.Text.Encoding.ASCII
            ping.StartInfo.StandardOutputEncoding = System.Text.Encoding.ASCII
            ping.Start()
            ping.BeginOutputReadLine()
            ping.WaitForExit()
            ping.OutputDataReceived -= pingOutputDataReceived
            MessageBox.Show(OutputMessage)
        End Sub
     
        Private Sub pingOutputDataReceived(ByVal sender As System.Object, ByVal e As DataReceivedEventArgs)
            OutputMessage += e.Data + Environment.NewLine
        End Sub
    Mais j'ai des erreurs :

    Public Event OutputDataReceived(sender As Object, e As System.Diagnostics.DataReceivedEventArgs)' est un événement. Il ne peut donc pas être appelé directement. Utilisez une instruction 'RaiseEvent' pour déclencher un événement.

    Public Event OutputDataReceived(sender As Object, e As System.Diagnostics.DataReceivedEventArgs)' est un événement. Il ne peut donc pas être appelé directement. Utilisez une instruction 'RaiseEvent' pour déclencher un événement.

  3. #23
    Invité
    Invité(e)
    Par défaut
    C'est que tu dois utiliser la méthode AddHandler en VB.Net et non le '+=' pour t'abonner aux évènements. Reste à confirmer !
    Dernière modification par Invité ; 24/05/2011 à 16h46.

  4. #24
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 63
    Points : 30
    Points
    30
    Par défaut
    J'ai rajouté :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    AddHandler ping.OutputDataReceived, pingOutputDataReceived()
    A la place de :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ping.OutputDataReceived += pingOutputDataReceived
    Mais je ne vois pas quoi mettre en paramètre de pingOutputDataReceived

  5. #25
    Invité
    Invité(e)
    Par défaut
    Code en VB.Net (Tu viens de déclencher mon allergie en début de journée et c'est pas top) :
    Code VB.Net : 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
     
    Dim ping As System.Diagnostics.Process = New System.Diagnostics.Process()
        Dim OutputMessage As String = New String("")
     
        'Bouton qui permet l'envoie d'un ping vers www.google.com
        Private Sub BT_PING_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BT_PING.Click
            ping = New Process()
            AddHandler ping.OutputDataReceived, AddressOf pingOutputDataReceived
            ping.StartInfo.FileName = "ping.exe"
            ping.StartInfo.Arguments = "www.google.com"
            ping.StartInfo.CreateNoWindow = True
            ping.StartInfo.UseShellExecute = False
            ping.StartInfo.RedirectStandardError = True
            ping.StartInfo.RedirectStandardOutput = True
            ping.StartInfo.StandardErrorEncoding = System.Text.Encoding.ASCII
            ping.StartInfo.StandardOutputEncoding = System.Text.Encoding.ASCII
            ping.Start()
            ping.BeginOutputReadLine()
            ping.WaitForExit()
            RemoveHandler ping.OutputDataReceived, AddressOf pingOutputDataReceived
            MessageBox.Show(OutputMessage)
        End Sub
     
        Private Sub pingOutputDataReceived(ByVal sender As System.Object, ByVal e As DataReceivedEventArgs)
            OutputMessage += e.Data + Environment.NewLine
        End Sub

    Conseil : un petit tour sur developpez.com ou sur le net pour lire les cours sur VB.Net serait un plus tu trouves pas ?

  6. #26
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 63
    Points : 30
    Points
    30
    Par défaut
    Le pire c'est que c'était dans l'exemple du lien que tu m'avais donné sur l'évènement... Je dois être aveugle désolé

    Merci cela fonctionne (y a juste les "é" qui sont remplacés par des "?")

  7. #27
    Invité
    Invité(e)
    Par défaut
    Pour cela tu dois jouer sur les valeurs de ces lignes en changeant les encodages et essayer autre chose que ASCII :
    Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    ping.StartInfo.StandardErrorEncoding = System.Text.Encoding.ASCII
    ping.StartInfo.StandardOutputEncoding = System.Text.Encoding.ASCII

  8. #28
    Inactif  
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2007
    Messages
    6 604
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6 604
    Points : 13 314
    Points
    13 314
    Par défaut
    Citation Envoyé par Nuage31 Voir le message
    Merci cela fonctionne (y a juste les "é" qui sont remplacés par des "?")
    Il serait peut être bien d'essayer de s'informer un minimum.

    Je ne réponds pas aux questions techniques par MP ! Le forum est là pour ça...


    Une réponse vous a aidé ? utiliser le bouton

    "L’ennui dans ce monde, c’est que les idiots sont sûrs d’eux et les gens sensés pleins de doutes". B. Russel

  9. #29
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 63
    Points : 30
    Points
    30
    Par défaut
    J'ai juste utilisé la fonction Replace.

  10. #30
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Nuage31 Voir le message
    J'ai juste utilisé la fonction Replace.
    Je ne pense que ça soit top d'utiliser la fonction Replace vu que les points '?' peuvent bien représenter tout caractère autre que 'é'.

    Mais bon fais comme tu veux.

  11. #31
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 63
    Points : 30
    Points
    30
    Par défaut
    Oui j'ai dû faire plusieurs replace vu que certains "?" étaient des espaces ou autres. Je me doute bien que c'est pas le mieux mais sur le coup j'avais pensé qu'à ça.

    Je vais tester en changeant l'encodage.

    Merci

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. script ping avec envoi de mail
    Par yoh852 dans le forum Scripts/Batch
    Réponses: 7
    Dernier message: 14/11/2011, 17h03
  2. [VB6] [Winsock] Envoi de données
    Par CYFL dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 25/12/2002, 17h49
  3. [Winsock] Envoi et recupération d'une image
    Par arnolanf dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 29/11/2002, 08h49
  4. [Socket]envoie de fichier!!!
    Par SamDaKap dans le forum C++Builder
    Réponses: 5
    Dernier message: 20/11/2002, 08h07
  5. Envoi de Datagrames par IP en JAVA
    Par the java lover dans le forum Développement
    Réponses: 2
    Dernier message: 14/08/2002, 11h44

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