Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to recognize if an app has been closed? (i have the task id) 1

Status
Not open for further replies.

ultra2

Programmer
Jun 26, 2005
46
HU
how to recognize if an app has been closed? (i have the task id)


TaskID = Shell filename, vbNormalFocus
...
I need to do some stuff if the started app has been closed.

plz help
 
Just try to open the process. If it opens, it exists, otherwise, terminated.
___
[tt]
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400

Private Sub Form_Load()
Dim ProcessId As Long
ProcessId = Shell("notepad.exe", vbNormalFocus)

'....

MsgBox IsProcessRunning(ProcessId)
End
End Sub

Function IsProcessRunning(pid As Long) As Boolean
Dim hProcess As Long
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
CloseHandle hProcess
IsProcessRunning = hProcess
End Function[/tt]
___

See also thread222-859655 for a synchronous solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top