Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Running applications

Posted on 1998-08-27
10
Medium Priority
?
147 Views
Last Modified: 2010-04-30
I need to run two applications.  But I need to wait for the first one to finish before I start the second one.  I'm using the Shell function to run both apps.  Is there another function that I can use to run an app and have it finish before the other starts?  
0
Comment
Question by:lafronte
  • 5
  • 4
10 Comments
 
LVL 3

Accepted Solution

by:
dapperry earned 200 total points
ID: 1431393
Yes there is.  You can use an API call to spawn the process.  I have a little routine here that does it.  It waits for the program to finish executing, before proceeding.  I think this should help.  By the way, I heard that in VB 6, that they will have an argument to the shell command, to do just this, but I'm not sure if thats just rumor.

Put this code in a new module:

'This module hosts the ExecCmd
'function, which allows you to
'execute a program, and then wait
'until the process is done, before
'returning to the calling procedure.
'

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 Const NORMAL_PRIORITY_CLASS = &H20&
      Private Const INFINITE = -1&

Public Sub 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.hProcess, INFINITE)
    ret& = CloseHandle(proc.hProcess)
End Sub


Then just call the ExecCmd function from anywhere in your project.
Let me know if you have any questions.

:) D Perry
0
 
LVL 3

Expert Comment

by:dapperry
ID: 1431394
Just to clarify.  So call your applications by using the ExecCmd function, instead of using Shell.

:) David
0
 
LVL 2

Expert Comment

by:dabellei
ID: 1431395
Sub commercial_apps(apps As String)
   
      Dim proc As PROCESS_INFORMATION
      Dim Start As STARTUPINFO
      Start.wShowWindow = False

      ' Initialize the STARTUPINFO structure:
      Start.cb = Len(Start)

      ' Start the shelled application:
          ret& = CreateProcessA(0&, apps, 0&, 0&, 1&, _
             NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc)
      End If
      ' Wait for the shelled application to finish:
      ret& = WaitForSingleObject(proc.hProcess, INFINITE)
      ret& = CloseHandle(proc.hProcess)
   
   
   
End Sub


call commercial_apps("application name and path")

This code is working very well i use it in my own programm..
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lafronte
ID: 1431396
I had not tried the code until recently but the problem I'm running into now is that it will wait for a period of time but not long enough.  The orginal application is still running when the second one is launched.  Should I change the INIFINITE?
0
 
LVL 3

Expert Comment

by:dapperry
ID: 1431397
Two questions - 1) What OS 2) What are you tring to run?  I've noticed that running control panel  applets do seem to time out waiting, but works for everything else.  Let me know and I'll see if I can help you out.

:) D Perry
0
 

Author Comment

by:lafronte
ID: 1431398
I had not tried the code until recently but the problem I'm running into now is that it will wait for a period of time but not long enough.  The orginal application is still running when the second one is launched.  Should I change the INIFINITE?
0
 

Author Comment

by:lafronte
ID: 1431399
The OS that I'm running is Win95 OSR2.  And my app is running the Share Agent for Oracle.  What happens is my app will launch the share agent and wait but when the share agent starts installing tools it exits the routine, while the share agent is still open, and continues through my code.  This will then launch Oracle Applications before it has been updated.  
0
 
LVL 3

Expert Comment

by:dapperry
ID: 1431400
Do you know if the Agent (the intial process) spawns off another process, and then closes itself, eg You are trying to launch a process that end up launching another process.  If so, we could have problems because the ExecCmd waits for 1 particular process to end.  Let me know if this is case.

:) D Perry
0
 
LVL 3

Expert Comment

by:dapperry
ID: 1431401
Also, is the app you are running 32-bit?

:) D Perry
0
 

Author Comment

by:lafronte
ID: 1431402
I think Oracle Installer does launch another process but initial process was never closed.  I'm pretty sure its a 16-bit app because it installs the 16 bit version of Oracle Applications.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question