|
|
Title | Start Notepad and wait for it to close in Visual Basic 2005 |
Description | This example shows how to start Notepad and wait for it to close in Visual Basic 2005. |
Keywords | start Notepad, start process, process, Notepad, VB2005 |
Categories | Windows, 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
|
|
|
|
|
|