Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleStart Notepad and wait for it to close in Visual Basic 2005
DescriptionThis example shows how to start Notepad and wait for it to close in Visual Basic 2005.
Keywordsstart Notepad, start process, process, Notepad, VB2005
CategoriesWindows, VB.NET, Software Engineering
 
This example shows how to start a process (in this case Notepad) and wait for it to finish.

When you click the Start Notepad button, the program creates a ProcessStartInfo object, passing it the name of the program to start.

It then creates a Process object and sets its StartInfo property to the ProcessStartInfo object. The code calls the Process's Start method to start the Notepad process and then calls WaitForExit so it waits until Notepad exits.

 
Private Sub btnStartNotepad_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnStartNotepad.Click
    ' Set start information.
    Dim start_info As New _
        ProcessStartInfo("C:\WINDOWS\NOTEPAD.EXE")
    start_info.UseShellExecute = False
    start_info.CreateNoWindow = True

    ' Make the process and set its start information.
    Dim proc As New Process
    proc.StartInfo = start_info

    ' Start the process.
    proc.Start()

    ' Wait until Notepad exits.
    proc.WaitForExit()

    MessageBox.Show("Exit Code: " & proc.ExitCode, "Exit " & _
        "Code", _
        MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated