Results 1 to 4 of 4

Thread: Shell And Wait for NT

  1. #1

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    This is in a book I've got, I can't remember the solution offhand But I'll post later.

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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.

  4. #4

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Thanks

    Thats it just thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width