Using the Shell function to run a program asynchronously 
Author Message
 Using the Shell function to run a program asynchronously

Hi,

I'm using the Shell function to e.g. ZIP-files.

How can I detemine that the ZIP-program is ready?

Harry



Fri, 17 Nov 2000 03:00:00 GMT  
 Using the Shell function to run a program asynchronously

Harry,

This question is asked approx twice a day. Answer lies at:

http://home.earthlink.net/~butlerbob/vb/tasks/shellwt.htm

Matthew



Quote:
> Hi,

> I'm using the Shell function to e.g. ZIP-files.

> How can I detemine that the ZIP-program is ready?

> Harry



Fri, 17 Nov 2000 03:00:00 GMT  
 Using the Shell function to run a program asynchronously

On Mon, 1 Jun 1998 22:13:46 +0200, "Harry van Nyendaal"

Quote:

>Hi,

>I'm using the Shell function to e.g. ZIP-files.

>How can I detemine that the ZIP-program is ready?

Another way to phrase the question (and come closer to a solution) is
"How can I determine when PKZIP is finished doing its business?"  In
other words, "How can I determine when a DOS program has finished
executing?"

Try using this code:
---------------------
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103&

' the following three API functions must be typed ALL ON ONE LINE
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal
hProcess As Long, lpExitCode As Long) As Long

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

Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long

Sub WaitForDOSApp(cmd As String)

    Dim ProcessId As Long, hProcess As Long
    Dim ExitCode As Long

    ProcessId = Shell(cmd, vbMinimizedNoFocus)
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, _
                False, ProcessId)
    Do
       Call GetExitCodeProcess(hProcess, ExitCode)
       DoEvents
    Loop While (ExitCode = STILL_ACTIVE)
    Call CloseHandle(hProcess)

End Sub

-----------------------------------------------------------

To use the above subroutine, pass the it command line you wish to
execute.  For example:

   WaitForDOSApp "c:\pkware\pkz204g.exe myfile.zip c:\*.doc"

The function will wait until the command is finish executing before
returning control to the Form or Subroutine which called it.  But note
the "DoEvents" call--this allows your form to process other events
while it is waiting.

                  :)  Pirate Pete the Christian Privateer  :)
                  :)             aka Jack Voltz            :)
                  :)      M  A  R  A  N  A  T  H  A  !     :)


                  Web page:  http://www.ovnet.com/~voltz
              Prolife page:  http://www.ovnet.com/~voltz/prolife.htm
                     Music: http://www.ovnet.com/~voltz/music.htm



Sun, 19 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Make SHELL run non-asynchronously?

2. Shell() running asynchronously w/ VB code

3. Advanced : Shell doesn't appear to be running asynchronously

4. Running a program after another using shell statement

5. Returning a value from a program that is running using the Shell command

6. Shell program: running IE in Shell

7. Close an app running under Shell function?

8. Help:Running DOS commands from SHELL function

9. Terminating a process/windows after running Shell Function

10. Running a Shell Function

11. Can I Asynchronously Execute a custom function

12. How to close program opened with shell function?

 

 
Powered by phpBB® Forum Software