Calling external exe files

maximc

Member
Joined
Apr 16, 2005
Messages
18
Programming Experience
1-3
I am using the inbuilt Shell() function to call a VB6 program but what happens is that the control after calling the .exe file does not wait to finish the job but goes ahead executing the rest of the commands within that module. How can I stop executing the rest of the statements in my current module until the called program has finished its job? Thanks.
 
Hi

If you use the System.Diagnostics.Process object rather than the older Shell method you can then instruct the Process to wait until it has exited before continuing with your code. At least, this is true for .NET 2.0 but I imagine the same works in .NET 1.1.

VB.NET:
Dim proc As New System.Diagnostics.Process
Proc.StartInfo.FileName = "calc.exe"
Proc.Start
Proc.WaitForExit
 
'Should only display once the calc application has finished
MessageBox.Show("Hello World!")


HTH

 
I modified my program as per your suggestion, but my program failed at the last statement Proc.WaitForExit. The system gave the following error message: No process is associated with this object. However, the program that I called, did actually execute and was still executing while the .Net program gave me the error.
 
please give more information about the application you were starting

is it run from a shortcut, batchfile or other indirect method?
is it a console or windows app?
is there any possibility you could upload the program to the board for review?
 
Well, here's the source code I am using in my VB.Net Program:
VB.NET:
ExecFile = MyPath + "\..\..\AIMvb6\tickets.exe"
MyFileInfo = New FileInfo(ExecFile)
Proc.Start(MyFileInfo.FullName, VB6Param + " 4")
'Proc.WaitForExit()
In the above code, tickets.exe is a VB6 program which I am calling from VB.Net
 
Last edited by a moderator:
Back
Top