
Tracking other processes with Visual Basic
All,
I'm having no luck in solving a problem that has been bothering me for a
while.
I want to spawn a process from my Visual Basic application, and then monitor
that process to take action when it has completed its run (due to an error
or otherwise) I have tried many things using various combinations of
shellexecute and watching window handles, with no luck. Here is where I am
currently:
' mark this as a running process
queuePtr.flag = "RUN"
' execute the application
r = ShellExecute(0, "open", queuePtr.executable, queuePtr.params, 0, 1)
queuePtr.hwnd = GetForegroundWindow()
lasthwnd = queuePtr.hwnd
' when the new window for the application pops up, record its handle
While lasthwnd = queuePtr.hwnd
queuePtr.hwnd = GetForegroundWindow()
DoEvents
Wend
' I should now have the correct handle in queuePtr.hwnd
Then, using a timer, I would check to see if the handle was gone. If it
was, I could take appropriate action.
If current.flag = "RUN" Then
tmp = IsWindow(current.hwnd)
If IsWindow(current.hwnd) = 0 Then
current.flag = "DONE"
End If
End If
This doesn't seem to work for me. Does anyone have an insight into why this
is not working? Or perhaps a better way to accomplish the same task?
Thanks a lot...
Phil Schaechter