How to determe when a SHELLed process ends. 
Author Message
 How to determe when a SHELLed process ends.

It's been a long time since I've used this, so I'm not too sure if it's from
MS KB or another source... anyways it's version 2 and works on NT4.

Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Integer) As
Integer

hModule = Shell(varBatch_File & " " & Format(Date, "mmmdd"), 1)
Do While GetModuleUsage(hModule)
       DoEvents
Loop

' varBatch_File is the name and path of a batch file read from an .INI file


Quote:
>I trying to find way to determine when a 32-bit shelled process ends in
>MS Access 95.  I attempted to implement the code example in the MS

[snip]

__

Dean Olynyk
ISM Information Systems Management Corp.
(204) 946-4807

Remove .NO_SPAM from E-Mail address to reply



Tue, 05 Oct 1999 03:00:00 GMT  
 How to determe when a SHELLed process ends.


says...

Quote:
> I don't think this works in Access 95. The GetModuleUsage function is only
> in the Win16 API, and can't be called by a 32 bit program. The
> documentation I've seen suggests using the Win32 API call to CreateProcess
> instead of Shell to start the program. CreateProcess returns a handle that
> you can with one of the Wait calls (WaitForSingleProcess?). I've only
> looked into this, not done it yet.

Here's code to do it:

' Code courtesy of:
' Microsoft Access 95 How-To
' Ken Getz and Paul Litwin
' Waite Group Press, 1996

Const PROCESS_QUERY_INFORMATION = &H400
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFFFFFF

Const STILL_ACTIVE = &H103&

Const ERR_FILE_NOT_FOUND = 53

Private Declare Function OpenProcess Lib "kernel32" ( _
 ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
 ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
 ByVal hProcess As Long, lpExitCode As Long) As Long

Sub ahtRunAppWait(strCommand As String, intMode As Integer)
   ' Run an application, waiting for its completion
   ' before returning to the caller.

   Dim hInstance As Long
   Dim hProcess As Long
   Dim lngRetval As Long
   Dim lngExitCode As Long

   On Error GoTo ahtRunAppWait_Err
   ' Start up the application.
   hInstance = Shell(strCommand, intMode)
   hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or SYNCHRONIZE, _
      True, hInstance)
   Do
      ' Attempt to retrieve the exit code, which will
      ' just not exist until the application has quit.
      lngRetval = GetExitCodeProcess(hProcess, lngExitCode)
      DoEvents
   Loop Until lngExitCode <> STILL_ACTIVE

ahtRunAppWait_Exit:
   Exit Sub

ahtRunAppWait_Err:
   Select Case Err.Number
      Case ERR_FILE_NOT_FOUND
         MsgBox "Unable to find '" & strCommand & "'"
      Case Else
         MsgBox Err.Description
   End Select
   Resume ahtRunAppWait_Exit
End Sub



Tue, 05 Oct 1999 03:00:00 GMT  
 How to determe when a SHELLed process ends.

I don't think this works in Access 95. The GetModuleUsage function is only
in the Win16 API, and can't be called by a 32 bit program. The
documentation I've seen suggests using the Win32 API call to CreateProcess
instead of Shell to start the program. CreateProcess returns a handle that
you can with one of the Wait calls (WaitForSingleProcess?). I've only
looked into this, not done it yet.
--
Paul Shapiro



Quote:
> It's been a long time since I've used this, so I'm not too sure if it's
from
> MS KB or another source... anyways it's version 2 and works on NT4.

> Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Integer)
As
> Integer

> hModule = Shell(varBatch_File & " " & Format(Date, "mmmdd"), 1)
> Do While GetModuleUsage(hModule)
>        DoEvents
> Loop

> >I trying to find way to determine when a 32-bit shelled process ends in
> >MS Access 95.  I attempted to implement the code example in the MS



Tue, 05 Oct 1999 03:00:00 GMT  
 How to determe when a SHELLed process ends.



Quote:
> While Ken's solution is explicitely "pooling", here is a solution
> "implicitly" doing it for you (the code is inspored from an article from
> the knowledge database, but unfortunately this morning, it is
> unaccessible). First, three Declare Statements:

Problem with this solution is that it doesn't let the application update
itself on the screen. Since many people want to run an app and watch it
run, I like the looping technique, which works in both situations. -- Ken


Fri, 08 Oct 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Why wait the end of a Shell process ?

2. Check if a Shell Process Ends

3. End a shell process ???

4. How a 32-Bit App Can Determine When a Shelled Process Ends, Article ID: Q129796

5. Help with Determining Shell Process Ends

6. Shell launch / Process End

7. How a 32-Bit App Can Determine When a Shelled Process Ends

8. Determine When shelled process end

9. Determining when a shelled process ends

10. Shelled Process does not end

11. How a 32-Bit APP can Determine When a Shelled Process Ends - Q129796

12. Help: Wait for shelled process to end

 

 
Powered by phpBB® Forum Software