Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shell Command: Wait for program to exit

Posted on 1999-07-30
2
Medium Priority
?
345 Views
Last Modified: 2011-10-03
Need I say more?  I need to wait for the program started by a shell command to complete before continuing processing.  Let me know if the question warrants more than 100 points.

Cheers-R
0
Comment
Question by:robholden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
EDDYT earned 400 total points
ID: 1528547
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


Private Declare Function CloseHandle Lib "kernel32" _
    (ByVal hObject As Long) As Long
    Public Const PROCESS_QUERY_INFORMATION = &H400
                                    
 

Sub Command1_Click()

    RunShell "c:\windows\notepad.exe"
End Sub

Private Sub RunShell (cmdline$)

    Dim hProcess As Long
    Dim ProcessId As Long
    Dim exitCode As Long
    ProcessId& = Shell(cmdline$, 1)
    hProcess& = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId&)


    Do
        Call GetExitCodeProcess(hProcess&, exitCode&)


        DoEvents
        Loop While exitCode& > 0

        MsgBox "The Shelled process " & cmdline$ & " has ended."
    End Sub

 

0
 

Author Comment

by:robholden
ID: 1528548
Great.  I made one small change - to make the WindowStyle parameter avalailable from the RunShell function.

Cheers-R
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

730 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