Launch a window application and wait for complete

Hi Expert,

Following code works fine if I want to launch an application program:

Sub LaunchApplication()
    Dim iAppID As Integer = Shell(appPath, AppWinStyle.MaximizedFocus)
    If System.IO.File.Exists(appPath) = True Then
        AppActivate(iAppID)
    Endif
End Sub

However, If I want to launch an application and force the operation system to wait until the application has been terminated before allowing any other action to be performed.  How do I do?  I  heard of ExecuteAndWait method. How does that work?  The code will be in form_load event.

Thanks very much

heartland
heartlandAsked:
Who is Participating?
 
Fernando SotoRetiredCommented:
Hi heartland;

The below code should do what you want.

Imports System.Diagnostics

Sub LaunchApplication()
    If System.IO.File.Exists(appPath) = True Then
        Dim p As Process
        p = Process.Start(appPath)
        p.WaitForExit()
End Sub

Fernando
0
 
Éric MoreauSenior .Net ConsultantCommented:
Hi heartland,

It is WaitForExit. See an article I wrote in December 2003 from http://emoreau.s2i.com/


Cheers!
0
 
heartlandAuthor Commented:
Hi Fernando,

I tried your code and it did the exactly what I wanted.  It is concise too.  Thanks for help.

Hugh
0
 
Fernando SotoRetiredCommented:
Glad I was able to help. :=)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.