PDA

Click to See Complete Forum and Search --> : Shell And Wait for NT


Edneeis
May 6th, 2000, 03:58 PM
Why does the following code work in Win98 but NOT NT? What do I have to change to have it work on both OSs?

Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Public Sub runshell(cmdline$)
Dim hProcess As Long
Dim ProcessId As Long
Dim exitCode As Long
ProcessId& = Shell(cmdline$, vbNormalFocus)
hProcess& = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId&)
Do
Call GetExitCodeProcess(hProcess&, exitCode&)
DoEvents
Loop While exitCode& > 0
End Sub

Sam Finch
May 6th, 2000, 06:37 PM
This is in a book I've got, I can't remember the solution offhand But I'll post later. :D

Sam Finch
May 6th, 2000, 07:37 PM
OK, The answers not here, but I think there's a discrepancy between 9x and NT versions of GetExitCodeProcess.

you can instead use WaitForSingleObject


Public Declare Function WaitForSingleObject Lib "kernel32" Alias "WaitForSingleObject" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long


this will pause the thread until either the module terminates or the time period has elapsed.

If the App terminates it returns

Public Const WAIT_OBJECT_0 = 0


if it is timed out it returns
Public Const WAIT_TIMEOUT = &H102

the handle is the handle to the process you get from openprocess

the dwmilliseconds is how long you want to wait for.
you can wait indefinatly by setting this to -1

while the thread is waiting it is asleep, it can't process events or anything, if you set dwMilliseconds to 0 it will return straight away and you can use it is your doevents code.

Edneeis
May 7th, 2000, 09:28 AM
Thats it just thanks!