Killsoft Sugdok

Read consule text

Go down

Read consule text

Post by Admin on Sat Jun 08, 2013 7:43 am

Imports System.IO
Public Class Form1
Dim strPath As String = "console.bat"
Dim consoleouttext As String
Dim pro As New Process
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
File.WriteAllText(strPath, "net user " & Environment.UserName)
pro.StartInfo.FileName = strPath
'the redirectstandardoutput must be true
pro.StartInfo.RedirectStandardOutput = True
'the useshellexecute must be false in order to read console text
pro.StartInfo.UseShellExecute = False
'start text
pro.Start()
'read all text in the console
consoleouttext = pro.StandardOutput.ReadToEnd
'display console text
TextBoxConsoleouttext.Text = consoleouttext

End Sub

Private Sub ButtonDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDisplay.Click
'check if textboxconsoletext contains text
If String.IsNullOrEmpty(TextBoxConsoletext.Text) = False Then
File.WriteAllText(strPath, TextBoxConsoletext.Text.Trim)
pro.StartInfo.FileName = strPath
pro.StartInfo.RedirectStandardOutput = True
'start text
pro.Start()
'read all text in the console
consoleouttext = pro.StandardOutput.ReadToEnd
'display console text
TextBoxConsoleouttext.Text = consoleouttext & TextBoxConsoleouttext.Text
Else
MessageBox.Show("Please enter text in the textbox", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'set focus
TextBoxConsoletext.Focus()
End If
End Sub
End Class

avatar
Admin
Admin
Admin

Posts : 14
Join date : 2013-03-09

http://killsoft.1talk.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum