Create Own Dos Prompt On VB.Net Form

Welcome To Our New Post, Today I'm Gonna Showed You How To Create Your Own DOS Prompt In VB.Net Using Form Application Project... So Let's Start------>

1. Open New Form Application VB.Net Project.



2. Goto Code Editor Window.


3. Now Paste Below Code Between Public Class Form1 And End Class





Code:

Private txtInput As New TextBox()
Private txtOutput As New TextBox()
Private btnSend As New Button()
Private strResults As String
Private intStop As Integer
Private swWriter As System.IO.StreamWriter
Private thrdCMD As System.Threading.Thread
Private Delegate Sub Update()
Private uFin As New Update(AddressOf UpdateText)

Private Sub Form1_Load(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles MyBase.Load

   txtOutput.Multiline = True
   txtOutput.Height = 200
   txtOutput.Dock = DockStyle.Fill
   txtOutput.ScrollBars = ScrollBars.Both
   txtOutput.BackColor = Color.Black
   txtOutput.ForeColor = Color.LightGray

   AddHandler txtOutput.KeyDown, AddressOf txtOutput_KeyDown
   Me.Controls.Add(txtOutput)

   thrdCMD = New System.Threading.Thread(AddressOf Prompt)

   thrdCMD.IsBackground = True

   thrdCMD.Start()

End Sub


Private Sub Prompt()

   Dim procCMDWin As New Process

   AddHandler procCMDWin.OutputDataReceived, _
      AddressOf CMDOutput

   procCMDWin.StartInfo.RedirectStandardOutput = True
   procCMDWin.StartInfo.RedirectStandardInput = True
   procCMDWin.StartInfo.CreateNoWindow = True

   procCMDWin.StartInfo.UseShellExecute = False


   procCMDWin.StartInfo.FileName = "cmd.exe"
   procCMDWin.StartInfo.WorkingDirectory = "c:\"

   procCMDWin.Start()

   procCMDWin.BeginOutputReadLine()

   swWriter = procCMDWin.StandardInput

   Do Until (procCMDWin.HasExited)
   Loop

   procCMDWin.Dispose()

End Sub


Private Sub UpdateText()

   txtOutput.Text += strResults

   txtOutput.SelectionStart = _
      txtOutput.TextLength - 1

   txtOutput.Focus()

   intStop = txtOutput.SelectionStart

   txtOutput.ScrollToCaret()

End Sub


Private Sub CMDOutput(ByVal Sender As Object, _
   ByVal OutputLine As DataReceivedEventArgs)

   strResults = OutputLine.Data & Environment.NewLine

   Invoke(uFin)

End Sub


Private Sub txtOutput_KeyDown(ByVal sender As System.Object, _
   ByVal e As System.Windows.Forms.KeyEventArgs)

   Select Case e.KeyCode

      Case Keys.Enter

         e.Handled = True

         txtOutput.SelectionStart = intStop
         txtOutput.SelectionLength = txtOutput.TextLength - 1

         Dim cmdToSend = txtOutput.SelectedText

         swWriter.WriteLine(cmdToSend & Environment.NewLine)

      Case Keys.Left, Keys.Right, Keys.Back

         If (txtOutput.SelectionStart < intStop) Then

            e.SuppressKeyPress = True

         End If

      Case Keys.Home

         txtOutput.SelectionStart = intStop

         e.SuppressKeyPress = True

      Case Keys.End

         txtOutput.SelectionStart = txtOutput.TextLength - 1

         e.SuppressKeyPress = True

      Case Else

         If ((e.KeyValue < 32) Or (e.KeyValue > 127)) Then

            e.SuppressKeyPress = True

         End If

   End Select

End Sub


Private Sub Form1_FormClosing(ByVal sender As System.Object, _
   ByVal e As System.Windows.Forms.FormClosingEventArgs) _
   Handles MyBase.FormClosing

   swWriter.Dispose()

End Sub


OUTPUT Would Be Like this....
👇🏻👇🏻👇🏻👇🏻






Comments

Popular Posts