1.

Solve : Start a program that uses cmd then enter commands and rename text displayed. VB?

Answer»

Ok so basically what im trying to do is have my program start an exe that uses command prompt. This exe will display text after the commands have been entered. I want to CHANGE the text that is displayed. something like .replace("The program is unable to connect to the default blablabla", "The program is unable to connect") but the thing is I'm using streamwriter to display this text within my program. Here have a look.

CODE: [Select]Imports System.IO

Public Class Form1

Dim SW As System.IO.StreamWriter
Dim Process As New Process

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


DevkitName.Text = My.Settings.DevkitNameSave
SaveLocation.Text = My.Settings.FolderPathSave

Dim filepath64 As String = "Program Files (x86)\Microsoft Xbox 360 SDK\bin\win32\xbmovie.exe"
Dim Filepath32 As String = "Program Files\Microsoft Xbox 360 SDK\bin\win32\xbmovie.exe"
Dim Path As String = My.Computer.FileSystem.CurrentDirectory.Substring(0, 3)
Dim drivespace As String = My.Computer.FileSystem.GetDriveInfo(Path).TotalFreeSpace / 1024 / 1024 / 1024

If My.Computer.FileSystem.FileExists(Path & filepath64) Then
ElseIf My.Computer.FileSystem.FileExists(Path & Filepath32) Then
Else
MessageBox.Show("The directory or file for xbmovie does not exist, make sure you have XBOX360 SDK aka Xbox 360 Neighborhood installed.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Label1.Text = "Drive Space Available: " & drivespace.ToString.Replace(".", " ").Substring(0, 4) & " GB"
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
FolderBrowserDialog1.Description = ("Select a place to save your VIDEO file.")
FolderBrowserDialog1.ShowDialog()
Dim save As String = FolderBrowserDialog1.SelectedPath
SaveLocation.Text = save
End Sub

Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
My.Settings.DevkitNameSave = DevkitName.Text
My.Settings.FolderPathSave = SaveLocation.Text
MessageBox.Show("Your save location and console name/ip settings have been saved.", "Settings Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Command As String = "/X:" & DevkitName.Text & " /F:6 " & SaveLocation.Text & "\" & VideoName.Text
Dim xbmovie As String = "xbmovie.exe "

If VideoName.Text = "" And DevkitName.Text = "" And SaveLocation.Text = "" Then
MessageBox.Show("You didn't enter any information", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf DevkitName.Text = "" And SaveLocation.Text = "" Then
MessageBox.Show("You need to enter a Devkit Name and Save Location", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf VideoName.Text = "" And SaveLocation.Text = "" Then
MessageBox.Show("You need to enter a Video Name and Save Location", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf VideoName.Text = "" And DevkitName.Text = "" Then
MessageBox.Show("You need to enter a Video Name and Devkit Name", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf VideoName.Text = "" Then
MessageBox.Show("You need to enter a Video Name", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf DevkitName.Text = "" Then
MessageBox.Show("You need to enter a Devkit Name", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf SaveLocation.Text = "" Then
MessageBox.Show("You need to enter a Save Location", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
'Cmd process start
AddHandler Process.OutputDataReceived, AddressOf DisplayOutput
Try
Button1.Enabled = False
Process.StartInfo.CreateNoWindow() = True

Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

Process.StartInfo.UseShellExecute = False

Process.StartInfo.RedirectStandardInput = True

Process.StartInfo.RedirectStandardOutput = True

Process.StartInfo.RedirectStandardError = True

Process.StartInfo.FileName = "Cmd"

Process.Start()

Process.SynchronizingObject = InfoBox

Process.BeginOutputReadLine()

SW = Process.StandardInput

SW.WriteLine("Test")

Catch ex As Exception
Return
End Try

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Button1.Enabled = True
End Sub



Private Sub DisplayOutput(ByVal sendingProcess As Object, ByVal output As DataReceivedEventArgs)

InfoBox.AppendText(output.Data() & vbCrLf)

End Sub



Private Sub InfoBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles InfoBox.KeyPress

Static Line As String

If e.KeyChar = Chr(Keys.Return) Then

SW.WriteLine(Line & vbCrLf)

Line = ""

Else

Line = Line & e.KeyChar

End If

End Sub
'cmd process end
End Class

Ok i have most code in place, here is a picture for reference.


All i want to do is not show the user the original text and change it.
I want the program to not show this text:
Code: [Select] Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Daniel\Desktop>"C:\Program Files (x86)\Microsoft Xbox 360 SDK\bin\win32\xbmovie.exe" /X:DaftHacker /F:6 C:\Users\Daniel\Desktop\Test.wmv

and change:
Code: [Select]Unable to connect to the runtime on target machine DaftHacker.

to something else, this part is written by the executed exe and not my program.

And here is the updated code

Code: [Select]Imports System.IO

Public Class Form1

Dim SW As System.IO.StreamWriter
Dim Process As New Process
Dim Path As String = My.Computer.FileSystem.CurrentDirectory.Substring(0, 3)

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


DevkitName.Text = My.Settings.DevkitNameSave
SaveLocation.Text = My.Settings.FolderPathSave

Dim filepath64 As String = "Program Files (x86)\Microsoft Xbox 360 SDK\bin\win32\xbmovie.exe"
Dim Filepath32 As String = "Program Files\Microsoft Xbox 360 SDK\bin\win32\xbmovie.exe"
Dim drivespace As String = My.Computer.FileSystem.GetDriveInfo(Path).TotalFreeSpace / 1024 / 1024 / 1024

If My.Computer.FileSystem.FileExists(Path & filepath64) Then
My.Settings.propath = filepath64
ElseIf My.Computer.FileSystem.FileExists(Path & Filepath32) Then
My.Settings.propath = Filepath32
Else
MessageBox.Show("The directory or file for xbmovie does not exist, make sure you have XBOX360 SDK aka Xbox 360 Neighborhood installed.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Label1.Text = "Drive Space Available: " & drivespace.ToString.Replace(".", " ").Substring(0, 4) & " GB"
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
FolderBrowserDialog1.Description = ("Select a place to save your video file.")
FolderBrowserDialog1.ShowDialog()
Dim save As String = FolderBrowserDialog1.SelectedPath
SaveLocation.Text = save
End Sub

Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
My.Settings.DevkitNameSave = DevkitName.Text
My.Settings.FolderPathSave = SaveLocation.Text
MessageBox.Show("Your save location and console name/ip settings have been saved.", "Settings Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim Command As String = " /X:" & DevkitName.Text & " /F:6 " & SaveLocation.Text & "\" & VideoName.Text & ".wmv"

If VideoName.Text = "" And DevkitName.Text = "" And SaveLocation.Text = "" Then
MessageBox.Show("You didn't enter any information", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf DevkitName.Text = "" And SaveLocation.Text = "" Then
MessageBox.Show("You need to enter a Devkit Name and Save Location", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf VideoName.Text = "" And SaveLocation.Text = "" Then
MessageBox.Show("You need to enter a Video Name and Save Location", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf VideoName.Text = "" And DevkitName.Text = "" Then
MessageBox.Show("You need to enter a Video Name and Devkit Name", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf VideoName.Text = "" Then
MessageBox.Show("You need to enter a Video Name", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf DevkitName.Text = "" Then
MessageBox.Show("You need to enter a Devkit Name", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
ElseIf SaveLocation.Text = "" Then
MessageBox.Show("You need to enter a Save Location", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If




AddHandler Process.OutputDataReceived, AddressOf DisplayOutput
Try
Button1.Enabled = False
Process.StartInfo.CreateNoWindow() = True

Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

Process.StartInfo.UseShellExecute = False

Process.StartInfo.RedirectStandardInput = True

Process.StartInfo.RedirectStandardOutput = True

Process.StartInfo.RedirectStandardError = True

Process.StartInfo.FileName = "Cmd"

Process.Start()

Process.SynchronizingObject = InfoBox

Process.BeginOutputReadLine()

SW = Process.StandardInput

SW.WriteLine(My.Settings.codepart & Path & My.Settings.propath & My.Settings.codepart & Space(1) & Command)


Catch ex As Exception
Return
End Try

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Button1.Enabled = True
End Sub



Private Sub DisplayOutput(ByVal sendingProcess As Object, ByVal output As DataReceivedEventArgs)

InfoBox.AppendText(output.Data() & vbCrLf)

End Sub



Private Sub InfoBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles InfoBox.KeyPress

Static Line As String

If e.KeyChar = Chr(Keys.Return) Then

SW.WriteLine(Line & vbCrLf)

Line = ""

Else

Line = Line & e.KeyChar

End If

End Sub
End Class

If you don't want to show output from the Command Prompt, then don't use the Command Prompt. No reason to start CMD when all you want to do is run xbmovie. As a console application it will create it's own console and you can easily hook into the standard output streams as you are doing with cmd.

meanwhile, if the program fails it MIGHT return an error code that you can check for. Process.Start() gives you a Process instance, and the ExitCode property will tell you the exitcode. Most programs will use non-zero to indicate a PROBLEM and 0 to indicate success.Quote from: BC_Programmer on November 12, 2012, 05:52:20 AM

If you don't want to show output from the Command Prompt, then don't use the Command Prompt. No reason to start CMD when all you want to do is run xbmovie. As a console application it will create it's own console and you can easily hook into the standard output streams as you are doing with cmd.

meanwhile, if the program fails it might return an error code that you can check for. Process.Start() gives you a Process instance, and the ExitCode property will tell you the exitcode. Most programs will use non-zero to indicate a problem and 0 to indicate success.
Well it's a form application and it's suppose to run cmd because xbmovie is a console application.Quote from: DaftHacker on November 12, 2012, 07:22:29 AM
Well it's a form application and it's suppose to run cmd because xbmovie is a console application.
cmd has nothing to do with console applications. cmd IS a console application, but it isn't used(inherently) for executing other console applications.


Quote from: BC_Programmer on November 12, 2012, 05:52:20 AM
As a console application it will create it's own console and you can easily hook into the standard output streams as you are doing with cmd.


Discussion

No Comment Found