opening two external programs sequentially

theboy419

Member
Joined
Nov 9, 2006
Messages
6
Programming Experience
3-5
I'm having a bit of a challenge... I'm a little new to VB.net as I've always used VB6 in the past but a few things have changed obviously. I'm trying to make my program open two external programs, one after the other. The code did so until I added the WaitForInputIdle and SendWait commands(I'm trying to open the program and automate its brief use from this other program using SendKeys). Now both open almost immediately, who the sendkeys function does do its job to the first one accordingly. The REAL problem however, isn't in it even openning both at ones. The problem is, once program 1 finishes, followed by program 2 finishing, the program is SOMEHOW stuck in a loop and just keeps reopenning both programs the same way it was. I already put in a variable at the beginning that incremented each time a program was openned, and it resets after the 2nd program so its somehow looping the code but i have no loop. This module is only connected to a push button to start it. Any ideas? Maybe a better way to do this? Thanks a ton!


Here's my code so far:
Private Function ExtProgRun() As Boolean
Dim myprocess as new System.Diagnostics.Process()
myprocess.startinfo.filename = "./apps/program1.exe"
myprocess.start
myProcess.WaitForInputIdle
System.Windows.Forms.SendKeys.SendWait("{ENTER}")
myProcess.WaitForExit()
myProcess.Close()

myprocess.startinfo.filename = "./apps/program2.exe"
myprocess.start
myProcess.WaitForExit()
myProcess.Close()


End Function
 
I already put in a variable at the beginning that incremented each time a program was openned,
What is this variable you speak of? I don't see it in your code.
How are you calling this function?

As written, the function returns no value and should perhaps be a sub instead (of course this could be a shortened version of a more complete function that does return a value?)
 
What is this variable you speak of? I don't see it in your code.
How are you calling this function?

As written, the function returns no value and should perhaps be a sub instead (of course this could be a shortened version of a more complete function that does return a value?)

The variable I was talking about i deleted, i just mentioned it to point out that the code is somehow repeating. I did change the function to a sub, it hadn't even hit me till you mentioned that. The problem still seems to remain though. :-/
 
Well, actually, I just found out apparently it is coming from the use of the "WaitForExit" command... i commented it out and it worked fine except that it openned program2 obviously right after program1 loaded instead of finished. Any easier way to solve this perhaps?
 
here's a quick example:
VB.NET:
    Private Sub RunProgs()
        Dim prc As New Process
        prc = prc.Start("Notepad.exe")
        prc.WaitForExit()
        prc = prc.Start("mspaint.exe")
        prc.WaitForExit()
    End Sub
it loads windows notepad then sits there until that instance of notepad is closed (other notepad windows can be open, but once the notepad that the program opened is closed your program moves on) then ms paint is opened
 
When you say it got locked in a loop - you dont think it could be because the SendKeys("ENTER") was sending the enter keypress to your own app, specifically the button that makes it go, do you? i.e. once you press the button once, SendKeys keeps on "pressing" it?


#Typically, sendkkeys is a lame way of doing process interaction.. Granted in some circumstances it is necessary, but sometimes it can be avoided. If you can provide more info about the apps, im sure people here wil lbe able to comment on whetehr we can get the window handles of the foreign apps buttons, and send WM_COMMAND messages into that apps windowing event queue using SendMessage - its much more reliable and less error prone than SendKeys
 
cjard,
Well, I thought so too but i commented that out in one of my attempts... so it was just the basic process setup like mentioned above, still opens more than once... it just doesn't add up :-/
 
I thought I mentioned, it's being called from the action of a button, on click. Sorry for not getting much of a chance to get on here lately and post any updates... i haven't had time to code, working OT and the likes has shortened my coding time :-/
 
VB.NET:
    'button "go" and the associated actions and checks involved    
    Sub GobuttonClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles gobutton.Click
        If program1.Checked = True Then
            ExtProgRun()
        End If
        If tuneup.Checked = True Then
            TuneupRun()
        End If
    End Sub
basically its a simple form with checkboxes and when you click the go button it sees what will get run
 
Last edited:
Back
Top