hungvb

App CMD

Sep 23rd, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.53 KB | None | 0 0
  1. Imports System.IO
  2. Public Class Form1
  3.     Private psi As ProcessStartInfo
  4.     Private cmd As Process
  5.     Private Delegate Sub InvokeWithString(ByVal text As String)
  6.     Public Sub runCMD()
  7.         Try
  8.             cmd.Kill()
  9.         Catch ex As Exception
  10.         End Try
  11.         rtbResult.Clear()
  12.         If txtCmd.Text.Contains("") Then
  13.             psi = New ProcessStartInfo(txtCmd.Text.Split(" ")(0), txtCmd.Text.Split(" ")(1))
  14.         Else
  15.             psi = New ProcessStartInfo(txtCmd.Text$)
  16.         End If
  17.         '    Dim systemencoding As System.Text.Encoding
  18.         System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
  19.         With psi
  20.             .UseShellExecute = False
  21.             .RedirectStandardError = True
  22.             .RedirectStandardOutput = True
  23.             .RedirectStandardInput = True
  24.             .CreateNoWindow = True
  25.             '   .StandardOutputEncoding = systemencoding
  26.             '  .StandardErrorEncoding = systemencoding
  27.         End With
  28.  
  29.  
  30.         cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
  31.         AddHandler cmd.ErrorDataReceived, AddressOf Async_Data_Received
  32.         AddHandler cmd.OutputDataReceived, AddressOf Async_Data_Received
  33.         cmd.Start()
  34.         cmd.BeginOutputReadLine()
  35.         cmd.BeginErrorReadLine()
  36.  
  37.     End Sub
  38.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  39.         runCMD()
  40.     End Sub
  41.     Private Sub Async_Data_Received(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
  42.         Me.Invoke(New InvokeWithString(AddressOf Sync_Output), e.Data)
  43.     End Sub
  44.     Private Sub Sync_Output(ByVal text As String)
  45.         rtbResult.AppendText(text & Environment.NewLine)
  46.         rtbResult.ScrollToCaret()
  47.     End Sub
  48.  
  49.     Private Sub CMDToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  50.         '  Input.text = ""
  51.     End Sub
  52.  
  53.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  54.         MessageBox.Show("Cảm Ơn Các Bạn Đã Sữ Dụng Ứng Dụng Của Bờm Khùng" & vbCrLf & "Bờm Khùng Blogger Luôn Cung Cấp Những Ứng Dụng Free Cho Mọi Người" & vbCrLf & "Và Không Đính Kèm Virus Nhé Mọi Người ", "Thông Báo")
  55.         Label1.Text = DateTime.Now.ToString
  56.  
  57.  
  58.     End Sub
  59.  
  60.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  61.      
  62.     End Sub
  63. End Class
Add Comment
Please, Sign In to add comment