Share via


How to: Determine If a Process Has Exited

You can use the HasExited property to determine if the process associated to a Process component has stopped running. The property value returns true if the process is closed and false if the process is still running.

Note

This value is only returned for processes that are started by a Process component.

The Process component does not need to close the associated process to obtain the HasExited property. Administrative information such as the HasExited and ExitTime properties are stored regardless of the way the associated process was closed. The information is stored even if the user closes the process by selecting the Close command in its interface. This information is useful if you want to make sure all processes started with your Process components close when you exit an application.

To determine if a process has exited

  • Read the HasExited property of the Process component that was used to open the process.

    The following example shows how to use the HasExited property to determine if the process associated with a Process component called Process1 has been closed. If it is open, call CloseMainWindow to close the application.

    If Not notepad.HasExited Then 
        ' If the process is still running, close it.
        notepad.CloseMainWindow()
    End If
    
    if (!notepad.HasExited)
            {
                notepad.CloseMainWindow();
            }
    

See Also

Tasks

How to: Specify Processes

How to: Stop Processes

Other Resources

Managing Processes

Retrieving Information About Processes