Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SHELL

6 views
Skip to first unread message

Jack Lowe

unread,
Oct 29, 1997, 3:00:00 AM10/29/97
to

Hi all,

When a task is started using the SHELL function, a TaskID is returned.

What can I do with that TaskID?

Specifically, is there some function that can be used to determine if that
task associated with that ID is still active?


Thanks... Jack

Stoil Marinov

unread,
Oct 29, 1997, 3:00:00 AM10/29/97
to Jack Lowe

Hi, Jack,

You could pass this ID to OpenProcess WinAPI, which will return a handle
to the process already started. Then you can use this handle in call to
WinAPI GetExitCodeProcess which if the process is still running will
return value of STILL_ACTIVE.

Here is a sample code:

'API constants used
Const PROCESS_QUERY_INFORMATION = &H400
Const STILL_ACTIVE = &H103

'API functions declarations
Declare Function GetExitCodeProcess Lib "kernel32" Alias
"GetExitCodeProcess" (ByVal hProcess As Long, lpExitCode As
Long) As
Long

Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess"
(ByVal
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal
dwProcessId As Long) As Long

Then use something like this to start the program and wait for it to
finish:
dim lProcessID as long
dim hProcess as long
dim lResult as long

lProcessID=Shell(...)

hProcess=OpenProcess(PROCESS_QUERY_INFORMATION, 0, lProcessID)

GetExitCodeProcess hProcess, lResult

'Loop until process is terminated
While lResult=STILL_ACTIVE
GetExitCodeProcess hProcess, lResult
DoEvents
Wend

'Program has finished

Regards,
Stoil

0 new messages