Here is the updated code, with a delegate used to update the text. Tested in 2005 and the code worked fine. There is an attachment of the new 2005 project example at the end of the post as well.
VB Code:
'Form code from sample project Private Results As String Private Delegate Sub delUpdate() Private Finished As New delUpdate(AddressOf UpdateText) Private Sub UpdateText() txtResults.Text = Results End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate) CMDThread.Start() End Sub Private Sub CMDAutomate() Dim myprocess As New Process Dim StartInfo As New System.Diagnostics.ProcessStartInfo StartInfo.FileName = "cmd" 'starts cmd window StartInfo.RedirectStandardInput = True StartInfo.RedirectStandardOutput = True StartInfo.UseShellExecute = False 'required to redirect StartInfo.CreateNoWindow = True 'creates no cmd window myprocess.StartInfo = StartInfo myprocess.Start() Dim SR As System.IO.StreamReader = myprocess.StandardOutput Dim SW As System.IO.StreamWriter = myprocess.StandardInput SW.WriteLine(txtCommand.Text) 'the command you wish to run..... SW.WriteLine("exit") 'exits command prompt window Results = SR.ReadToEnd 'returns results of the command window SW.Close() SR.Close() 'invokes Finished delegate, which updates textbox with the results text Invoke(Finished) End Sub




Reply With Quote