|
-
May 6th, 2000, 03:58 PM
#1
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
-
May 6th, 2000, 06:37 PM
#2
Frenzied Member
This is in a book I've got, I can't remember the solution offhand But I'll post later.
-
May 6th, 2000, 07:37 PM
#3
Frenzied Member
OK, The answers not here, but I think there's a discrepancy between 9x and NT versions of GetExitCodeProcess.
you can instead use WaitForSingleObject
Code:
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
Code:
Public Const WAIT_OBJECT_0 = 0
if it is timed out it returns
Code:
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.
-
May 7th, 2000, 09:28 AM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|