0

I'm new to coding. I'm cant seem to figure out/find a solution on how to make my code work correctly when I try to execute. I have built a VB form that creates a command string in a TextBox depending on selections made from a variety of form selections. I'm appending text to the textbox per the selections to create said command string. Once the command is finished being built I want to be able to execute the built textbox.text using a button to execute it, and have the output be displayed in a RichTextBox in my form.

added info. Below is the section of code I'm trying to get working. I wasn't sure if I should add the code to the post or not after reading the creating a post section. lets say the text in the textbox1 would be something like.

psexec.exe \PCname c:\program files\mcafee\virusscan enterprise\mcupdate.exe \update \quiet

    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
    System.Windows.Forms.Application.DoEvents()
    Dim myprocess As New Process
    Dim startinfo As New ProcessStartInfo("cmd.exe")
    startinfo.Arguments = TextBox1.Text
    startinfo.UseShellExecute = False
    startinfo.RedirectStandardOutput = True
    startinfo.CreateNoWindow = True
    myprocess.StartInfo = startinfo
    myprocess.StartInfo.Arguments = TextBox1.Text
    myprocess.Start()
    Dim str1 As String = ""
    Using MyStreamReader As IO.StreamReader = myprocess.StandardOutput
        str1 = str1 & MyStreamReader.ReadToEnd
    End Using
    RichTextBox1.Text = str1
    end sub

Note: Working version is below.

    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles   Button12.Click
    System.Windows.Forms.Application.DoEvents()
    Dim myprocess As New Process
    Dim startinfo As New ProcessStartInfo(TextBox3.Text, TextBox1.Text)
    startinfo.UseShellExecute = False
    startinfo.RedirectStandardOutput = True
    startinfo.CreateNoWindow = True
    myprocess.StartInfo = startinfo
    myprocess.Start()
    Dim str1 As String = ""
    Using MyStreamReader As IO.StreamReader = myprocess.StandardOutput
        str1 = str1 & MyStreamReader.ReadToEnd
    End Using
    RichTextBox1.Text = str1
End Sub
cdch
  • 3
  • 2
  • 1
    Nobody can help you debug/fix code that is nowhere to be seen. See the [Help Centre](https://stackoverflow.com/help) about [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Add a description of what you mean when you refer to a *Form that creates a command string* and *execute the built textbox.text*. – Jimi Aug 28 '19 at 17:48
  • please see edited post – cdch Aug 28 '19 at 18:43
  • You may want to verify your `PsExec` switches here: [PsExec](https://www.itprotoday.com/compute-engines/psexec) (that blog is Mark Russinovich's, the author). Especially `-u`, `-p`, and `-i`. Also, **take a look at the Date** when that article was written. In any case, I suggest you test the `Process` functionality with something like this: [How To Output Shell Command To a RichTextBox In Visual Basic](https://stackoverflow.com/a/51313844/7444103) – Jimi Aug 28 '19 at 19:27
  • I was able to get my code to execute with the help of a coworker. I will and a note above in the original post. – cdch Aug 29 '19 at 19:39

0 Answers0