Waiting for an application to finish executing before executing next app 
Author Message
 Waiting for an application to finish executing before executing next app

I have a VB app that are going to launch 3 different executables. Each of
them have to finish executing before the next is executed. All of them are
executed in silent, no UI, no windows.

I have looked at the Shell function that returns a taskid but haven't found
any way to use the taskid.

I also looked a using the FindWindow from the WINAPI but my apps doesn't
have a window to look for.

Any other suggestions how this can be done?

Thanks
Lars Nielsen



Mon, 24 Feb 2003 06:57:43 GMT  
 Waiting for an application to finish executing before executing next app

Lars,

Check out the WaitForSingleObject API function.  I think this is what you are
looking for.

---
Hope this helps,
Mark

Quote:

> I have a VB app that are going to launch 3 different executables. Each of
> them have to finish executing before the next is executed. All of them are
> executed in silent, no UI, no windows.

> I have looked at the Shell function that returns a taskid but haven't found
> any way to use the taskid.

> I also looked a using the FindWindow from the WINAPI but my apps doesn't
> have a window to look for.

> Any other suggestions how this can be done?

> Thanks
> Lars Nielsen



Mon, 24 Feb 2003 10:30:55 GMT  
 Waiting for an application to finish executing before executing next app

I looked into that but it does not seem to work with a task id.
WaitForSingleObject fails immediately if I pass on a task id.


Quote:
> Lars,

> Check out the WaitForSingleObject API function.  I think this is what you
are
> looking for.

> ---
> Hope this helps,
> Mark


> > I have a VB app that are going to launch 3 different executables. Each
of
> > them have to finish executing before the next is executed. All of them
are
> > executed in silent, no UI, no windows.

> > I have looked at the Shell function that returns a taskid but haven't
found
> > any way to use the taskid.

> > I also looked a using the FindWindow from the WINAPI but my apps doesn't
> > have a window to look for.

> > Any other suggestions how this can be done?

> > Thanks
> > Lars Nielsen



Mon, 24 Feb 2003 09:24:40 GMT  
 Waiting for an application to finish executing before executing next app

Lars,

Ok, I see.  Try something like this.

Private Const SYNCHRONIZE = &H100000

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As
Long, _
     ByVal dwMilliseconds As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As
Long, _
     ByVal bInheritHandle As Long, _
     ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As
Long

Private Sub Command1_Click()

    Dim task_id As Long
    Dim process_handle As Long

    task_id = Shell("telnet.exe", vbNormalFocus)
    process_handle = OpenProcess(SYNCHRONIZE, 0, task_id)
    WaitForSingleObject process_handle, 60000   ' Use -1 here to wait forever
    CloseHandle process_handle

End Sub

---
Hope this helps,
Mark

Quote:

> I looked into that but it does not seem to work with a task id.
> WaitForSingleObject fails immediately if I pass on a task id.



> > Lars,

> > Check out the WaitForSingleObject API function.  I think this is what you
> are
> > looking for.

> > ---
> > Hope this helps,
> > Mark


> > > I have a VB app that are going to launch 3 different executables. Each
> of
> > > them have to finish executing before the next is executed. All of them
> are
> > > executed in silent, no UI, no windows.

> > > I have looked at the Shell function that returns a taskid but haven't
> found
> > > any way to use the taskid.

> > > I also looked a using the FindWindow from the WINAPI but my apps doesn't
> > > have a window to look for.

> > > Any other suggestions how this can be done?

> > > Thanks
> > > Lars Nielsen



Mon, 24 Feb 2003 12:18:26 GMT  
 Waiting for an application to finish executing before executing next app


Fri, 19 Jun 1992 00:00:00 GMT  
 Waiting for an application to finish executing before executing next app
Check out:

http://support.microsoft.com/support/kb/articles/Q129/7/96.ASP

Good luck,

--
----
Kind regards

Andy De Filippo



Mon, 24 Feb 2003 21:23:58 GMT  
 Waiting for an application to finish executing before executing next app


Fri, 19 Jun 1992 00:00:00 GMT  
 Waiting for an application to finish executing before executing next app
Thanks a lot Mark, that made it work.

Lars


Quote:
> Lars,

> Ok, I see.  Try something like this.

> Private Const SYNCHRONIZE = &H100000

> Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As
> Long, _
>      ByVal dwMilliseconds As Long) As Long
> Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As
> Long, _
>      ByVal bInheritHandle As Long, _
>      ByVal dwProcessId As Long) As Long
> Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long) As
> Long

> Private Sub Command1_Click()

>     Dim task_id As Long
>     Dim process_handle As Long

>     task_id = Shell("telnet.exe", vbNormalFocus)
>     process_handle = OpenProcess(SYNCHRONIZE, 0, task_id)
>     WaitForSingleObject process_handle, 60000   ' Use -1 here to wait
forever
>     CloseHandle process_handle

> End Sub

> ---
> Hope this helps,
> Mark


> > I looked into that but it does not seem to work with a task id.
> > WaitForSingleObject fails immediately if I pass on a task id.



> > > Lars,

> > > Check out the WaitForSingleObject API function.  I think this is what
you
> > are
> > > looking for.

> > > ---
> > > Hope this helps,
> > > Mark


> > > > I have a VB app that are going to launch 3 different executables.
Each
> > of
> > > > them have to finish executing before the next is executed. All of
them
> > are
> > > > executed in silent, no UI, no windows.

> > > > I have looked at the Shell function that returns a taskid but
haven't
> > found
> > > > any way to use the taskid.

> > > > I also looked a using the FindWindow from the WINAPI but my apps
doesn't
> > > > have a window to look for.

> > > > Any other suggestions how this can be done?

> > > > Thanks
> > > > Lars Nielsen



Tue, 25 Feb 2003 01:46:24 GMT  
 Waiting for an application to finish executing before executing next app

One more question. The solution works calling notepad.exe but if I try to
call any setup.exe (InstallShield installations). The application runs but I
don't get a task id back from the call to Shell.

Any suggestions
Thanks, Lars


Quote:
> Lars,

> Ok, I see.  Try something like this.

> Private Const SYNCHRONIZE = &H100000

> Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As
> Long, _
>      ByVal dwMilliseconds As Long) As Long
> Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As
> Long, _
>      ByVal bInheritHandle As Long, _
>      ByVal dwProcessId As Long) As Long
> Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long) As
> Long

> Private Sub Command1_Click()

>     Dim task_id As Long
>     Dim process_handle As Long

>     task_id = Shell("telnet.exe", vbNormalFocus)
>     process_handle = OpenProcess(SYNCHRONIZE, 0, task_id)
>     WaitForSingleObject process_handle, 60000   ' Use -1 here to wait
forever
>     CloseHandle process_handle

> End Sub

> ---
> Hope this helps,
> Mark


> > I looked into that but it does not seem to work with a task id.
> > WaitForSingleObject fails immediately if I pass on a task id.



> > > Lars,

> > > Check out the WaitForSingleObject API function.  I think this is what
you
> > are
> > > looking for.

> > > ---
> > > Hope this helps,
> > > Mark


> > > > I have a VB app that are going to launch 3 different executables.
Each
> > of
> > > > them have to finish executing before the next is executed. All of
them
> > are
> > > > executed in silent, no UI, no windows.

> > > > I have looked at the Shell function that returns a taskid but
haven't
> > found
> > > > any way to use the taskid.

> > > > I also looked a using the FindWindow from the WINAPI but my apps
doesn't
> > > > have a window to look for.

> > > > Any other suggestions how this can be done?

> > > > Thanks
> > > > Lars Nielsen



Tue, 25 Feb 2003 03:00:37 GMT  
 Waiting for an application to finish executing before executing next app
Thanks for the link. I tried it. I can make it work notepad.exe but can't
make it work with the setup.exe from InstallShield. It is{*filter*} but when I
kill the VB app, setup runs. It looks like they are running in the same
process and locks each up somehow.

Any suggestions
Thanks, Lars

Any suggestions


Quote:
> Check out:

> http://www.*-*-*.com/

> Good luck,

> --
> ----
> Kind regards

> Andy De Filippo




Tue, 25 Feb 2003 03:09:43 GMT  
 Waiting for an application to finish executing before executing next app

Hi Lars,

The setup.exe that is generated by InstallShield is a 16 bit application so
WaitForSingleObject will not work because all 16 bit applications run in
the same process space. Also, there is another problem with InstallShield.
On launching the setup.exe , a setup engine is started. This is when the
progress bar starts from 0% to 100% starts. Moment the progress bar
finishes 100% , it instantias the setup wizard (or the Blue or green screen
in lay-man's language) and the setup engine terminates . So you can see
there are actually two process running one after the other. To put in other
words , for each application , there are two process running one after the
other when you click on setup.exe. So even you can get it work in VB and
use WaitForSingleObject to detect when it terminates, the
WaitForSingleObject will return when the first process(setup.exe) returns.

To workaround the above two problems, you can try the following code and
see if it works on your side.

Private 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

Private Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessID As Long
  dwThreadId As Long
End Type

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

Private 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

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

Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess
As Long, lpExitCode As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Const NORMAL_PRIORITY_CLASS = &H20&

Private Const INFINITE = -1&

Public Function ExecCmd(cmdline$)

  Dim proc As PROCESS_INFORMATION

  Dim start As STARTUPINFO

  ' Initialize the STARTUPINFO structure:

  start.cb = Len(start)

  ' Start the shelled application:

  ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS,
0&, 0&, start, proc)

  ' Wait for the shelled application to finish:

  'ret& = WaitForSingleObject(proc.hThread, INFINITE)

  'Call GetExitCodeProcess(proc.hThread, ret&)

  'Call CloseHandle(proc.hThread)

  Do

  ret& = WaitForSingleObject(proc.hProcess, 0)

  DoEvents

  Loop Until ret& <> 258

  ret& = CloseHandle(proc.hProcess)

  ExecCmd = ret&

End Function

Sub Form_Click()

  Dim RetVal As Long

  RetVal = ExecCmd("D:\My Installations\TestApp\Media\TestApp\Disk
Images\disk1\setup.exe")

  WaitForInstallShieldToStop "InstallShield_Win"

  MsgBox "Process Finished, Exit Code " & RetVal

End Sub

Private Sub WaitForInstallShieldToStop(strClassName As String)

   Dim lngFoundhWnd As Long

   On Error GoTo WaitForInstallShieldToStop_EH

   ' Usage:

   ' WaitForInstallShieldToStop "ISINSTALLSCLASS"

   lngFoundhWnd = FindWindow(strClassName, vbNullString)

   Do Until lngFoundhWnd = 0

       DoEvents

       Sleep 100

       lngFoundhWnd = FindWindow(strClassName, vbNullString)

   Loop

   Exit Sub

WaitForInstallShieldToStop_EH:

   Exit Sub

End Sub

Best Regards,
Elan Zhou



Tue, 25 Feb 2003 12:24:14 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Shell - Wait for shelled app to load then execute next line of code

2. Wait until logonscript finishes executing...

3. Executing a shell command, waiting for it to finish, getting its return code

4. Executing a shell command, waiting for it to finish, getting its return code

5. how to wait before executing next line w/Inet1

6. Execute application and wait problem

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

8. determine when query finish executing

9. Query Not Finished Executing

10. Wait for "Shell"-ed app to finish

11. Waiting for an app to finish processing...

12. Waiting for an app to finish

 

 
Powered by phpBB® Forum Software