Advertisement
andrzejiwaniuk

[Napisz sam] Polecenie PING i TRACERT uruchomione z własnego

Jun 22nd, 2013
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace WierszPolecen1
  17. {
  18.     /// <summary>
  19.     /// Program do uzywania polecenia Ping zaimplementowanego w systemie Windows
  20.     /// </summary>
  21.     public partial class MainWindow : Window
  22.     {
  23.         static String polecenie;
  24.        
  25.         public MainWindow()
  26.         {
  27.             InitializeComponent();
  28.         }
  29.  
  30.         private void btnPolecenie_Click(object sender, RoutedEventArgs e)
  31.         {
  32.                
  33.            
  34.             MessageBox.Show(polecenie);
  35.             try
  36.             {
  37.                 System.Diagnostics.ProcessStartInfo procStartInfo =
  38.                     new System.Diagnostics.ProcessStartInfo("cmd", "/c " + polecenie);
  39.                 procStartInfo.UseShellExecute = true;
  40.                        
  41.                 System.Diagnostics.Process proc = new System.Diagnostics.Process();
  42.                 proc.StartInfo = procStartInfo;
  43.                 proc.Start();
  44.             }
  45.             catch (Exception e1)
  46.             {
  47.                 MessageBox.Show(e1.Message);
  48.             }
  49.         }
  50.  
  51.         private void rbPing_Checked(object sender, RoutedEventArgs e)
  52.         {
  53.             polecenie = "ping " + txtIPDomain.Text;
  54.         }
  55.  
  56.         private void rbTracert_Checked(object sender, RoutedEventArgs e)
  57.         {
  58.             polecenie = "tracert " + txtIPDomain.Text;
  59.         }
  60.  
  61.         private void txtIPDomain_TextChanged(object sender, TextChangedEventArgs e)
  62.         {
  63.             if (!txtIPDomain.Text.Equals(""))
  64.             {
  65.                 rbPing.IsEnabled = true;
  66.                 rbTracert.IsEnabled = true;
  67.                 btnPolecenie.IsEnabled = true;
  68.             }
  69.             else
  70.             {
  71.                 rbPing.IsEnabled = false;
  72.                 rbTracert.IsEnabled = false;
  73.                 btnPolecenie.IsEnabled = false;
  74.             }
  75.         }
  76.  
  77.         private void btnZamknij_Click(object sender, RoutedEventArgs e)
  78.         {
  79.             this.Close();
  80.            
  81.         }
  82.  
  83.        
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement