I am trying to create a gui that will interact with an existing external console application, e.g. the user only changes information in text boxes or radio buttons and that will prompt the VB.net program to sumbit a certain set of commands. I will create a folder for the end user that has only two programs in it, the VB.exe and the OtherProgram.exe. I have tried using ProcessStart with SendKeys to send information to the terminal with limited success (errors include multiple instances opening, entering "ttttttteeeeeeexxxxxxtttttt" instead of "text") and also Shell(OtherProgram.exe) and SendKeys with the same result.

I am trying to make an easier experience for using a legacy Fortran.exe program rather than every user going though the command prompts in the terminal window. Thanks in advance for your help!

Recommended Answers

All 4 Replies

Also, I am sure timing is an issue, I attemped to include Threading.Thread.Sleep(1000) to give the external application time to execute, but still no desirable results.

In order to understand what are you doing, and be able to try to help you, please, be so kind to post your coding so far and comment it indicating where you find the problems, the expected resutls and the actual ones.

Thanks in advance

Sorry for the delay, it has been a rough week at work. Thanks in advance. The code seems to be opening the .exe program and entering the information but it it only works approx 1 in 10 tries, the other times it opens multiple instances and freezes. and help will be greatly appreciated.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RunMillnas.Click

        Dim P As New ProcessStartInfo
        Dim sourceName As String
        'One file parameter to the executable
        If ckbNew.Checked = True Then
            sourceName = txtINP.Text
        Else
            sourceName = txtInpNew.Text + ".inp"
        End If


        'Specify the location of the binary
        P.FileName = "command_line.exe"

        ''Use a hidden window
        'P.WindowStyle = ProcessWindowStyle.Hidden

        'Start the process
        'Dim StartInfo As New System.Diagnostics.ProcessStartInfo()
        Process.Start(P)
        Threading.Thread.Sleep(500)
        SendKeys.Send("{ENTER}")
        SendKeys.Flush()
        Threading.Thread.Sleep(1000)
        SendKeys.Flush()
        SendKeys.Send("hello")
        SendKeys.Flush()
        Threading.Thread.Sleep(1000)
        SendKeys.Send("{ENTER}")
        SendKeys.Flush()
        Threading.Thread.Sleep(1000)
        SendKeys.Send(sourceName)
        SendKeys.Flush()
        Threading.Thread.Sleep(1000)
        SendKeys.Send("{ENTER}")

    End Sub

I used ProcessStart sucessfully after I changed the Fortran program to accept argments upon opening. The SendKeys seems to always be a bad idea lol.

Private Sub RunMillnas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RunMillnas.Click

        Dim P As New ProcessStartInfo
        Dim sourceName As String = ""

        If ckbNew.Checked = False Then
            sourceName = txtInpNew.Text & ".inp"
        End If

        '' Specify the location of the binary
        P.FileName = "millnas-vb-2012-07-01.exe"
        P.UseShellExecute = False

        '' Use these arguments for the process (covers all conditions for possible arguments)
        If ckbNew.Checked = True And ckbSetFile.Checked = True Then
            P.Arguments = (gNastranFile & "," & gInputFile & "," & gSetFile)
        ElseIf ckbNew.Checked = True And ckbSetFile.Checked = False Then
            P.Arguments = (gNastranFile & "," & gInputFile)
        ElseIf ckbNew.Checked = False And ckbSetFile.Checked = True Then
            P.Arguments = (gNastranFile & "," & sourceName & "," & gSetFile)
        ElseIf ckbNew.Checked = False And ckbSetFile.Checked = False Then
            P.Arguments = (gNastranFile & "," & sourceName)
        End If

        '' Use a hidden window, ensures millnas window is not seen by user
        P.WindowStyle = ProcessWindowStyle.Hidden

        '' Start the process
        Process.Start(P)
        MessageDisplayOK("Millnas is running in the background")

    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.