Wait for "Shell"-ed app to finish 
Author Message
 Wait for "Shell"-ed app to finish

How can make sure that my procedure won't continue until the application I
start has completed?

Thanks



Tue, 10 Apr 2001 03:00:00 GMT  
 Wait for "Shell"-ed app to finish
You could use my Fileprocess dll available at:
http://www.bcsupernet.com/users/Murray/vbhomepage/fileprocess/index.htm
200+ file,directory,drive functions. Not for VB4, Vb3 or windows 3.1.

Best wishes, Murray

'Wait for an "AppShell" launched application to finish
' before continuing the next statement
'Case 1 Launch the windows calculator
        Dim myFile as New clFile
        myFile = "calc.exe"
        myFile.AppShell
        myfile.AppSendKeys "%VS"  ' Start in Scientific Mode
        myFile.AppWaitForCompletion
        x = 1   'executed when calc.exe finishes  



Tue, 10 Apr 2001 03:00:00 GMT  
 Wait for "Shell"-ed app to finish
There is also an api that you can call that is simple to use. So simple I
don't remember what it is but I used it in a program at work. Maybe someone

and i'll send it to you.
Quote:

> How can make sure that my procedure won't continue until the application I
> start has completed?

> Thanks



Tue, 10 Apr 2001 03:00:00 GMT  
 Wait for "Shell"-ed app to finish

Quote:

>How can make sure that my procedure won't continue until the application I
>start has completed?

>Thanks

You need to use the OpenProcess() Api call to shell your program rather than
the Vb Shell Function. This
returns the handle to the shelled process for use by the WaitForSingleObject
API call.
I posted the following sub in response to a similar problem some weeks back;
the sub wraps this up the above API functions:

' *****Declarations*****

Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Public Const SW_SHOW& = 5 'sets nShowCmd param in ShellExecute API function
Public Const SW_HIDE& = 0
Public Const STARTF_USESHOWWINDOW& = &H1

Public Type STARTUPINFO
         cb As Long
         lpReserved As String
         lpDesktop As String
         lpTitle As String
         dwX As Long
         dwY As Long
         dwXSize As Long
         dwYSize As Long
         dwXCountChars As Long
         dwYCountChars As Long
         dwFillAttribute As Long
         dwFlags As Long
         wShowWindow As Integer
         cbReserved2 As Integer
         lpReserved2 As Long
         hStdInput As Long
         hStdOutput As Long
         hStdError As Long
End Type

Public Type PROCESS_INFORMATION
   hProcess As Long
   hThread As Long
   dwProcessID As Long
   dwThreadID As Long
End Type

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

Public Declare Function CreateProcessA Lib "kernel32" (ByVal _
   lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
   lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
   ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
   ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
   lpStartupInfo As STARTUPINFO, lpProcessInformation As _
   PROCESS_INFORMATION) As Long

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

'*****End Of Declarations*****

Public Sub OpenProcess(cmdline$) 'takes path to shelled app as a parameter
   Dim start As STARTUPINFO
   Dim proc As PROCESS_INFORMATION
   Dim lngreturn As Long

   ' Initialize the STARTUPINFO structure:
   start.cb = Len(start)
   start.dwFlags = STARTF_USESHOWWINDOW 'forces functn to use wShowWindow
param below
   start.wShowWindow = SW_HIDE 'shelled process is HIDDEN. Use SW_SHOW etc
to run visible

   ' Start the shelled application:
   lngreturn = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
      NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

   ' Wait for the shelled application to finish:
   lngreturn = WaitForSingleObject(proc.hProcess, INFINITE)
   lngreturn = CloseHandle(proc.hProcess)
End Sub

See Q129796 in the Knowledge Base for further details of this.



Wed, 11 Apr 2001 03:00:00 GMT  
 Wait for "Shell"-ed app to finish

Quote:

> There is also an api that you can call that is simple to use. So simple I
> don't remember what it is but I used it in a program at work. Maybe someone

> and i'll send it to you.


> > How can make sure that my procedure won't continue until the application I
> > start has completed?

> > Thanks

You can use one of the 3 following APIs:

GetModuleUsage
GetExitCodeProcess
WaitForSingleObject

Alex.



Fri, 27 Apr 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Waiting for 'SHELL'ed application to finish

2. When is "SHELL"ed Application terminated???

3. Waiting for Shelled App to finish before resuming execution of parent app

4. Shell and Wait "REMNANTS"

5. DOS App, Detecting "FINISHED"

6. Waiting For A Shelled DOS App to Finish...

7. Waiting for a shelled app to finish

8. "shell" cmd - app starts minimized

9. Removing a "Finished" DOS window invoked via "shell"

10. Determine if dynamic has "redim"ed

11. Use Win95 API in VB4 to Wait for a Shell'ed Program to Complete

12. Script closes "finished" DOS window

 

 
Powered by phpBB® Forum Software