Discussion Locked

VB - how to run another program

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

The catch here is that I want to wait until the program finishes before the program continues with the next statement,i.e. I want to run it sychronously rather than async, which is what shell does. There may be some way to start it with shell and then check the task id to see when it quits.

Thanks,
Steve

7 replies

by roc180

There is a ShellAndWait API, where you can shell to an application and control will not be returned until the shelled application closes. If you want a VB example, drop me a line and I can Email it to you.

Neal Martinelli

by a h

Declerations
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 Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
====
Code
====
Sub Shell32Bit(ByVal JobToDo As String)

Dim hProcess As Long
Dim RetVal As Long
'The next line launches JobToDo as icon,

'captures process ID
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 1))

Do

'Get the status of the process
GetExitCodeProcess hProcess, RetVal

'Sleep command recommended as well as DoEvents
DoEvents: Sleep 100

Loop While RetVal = STILL_ACTIVE
End Sub

This discussion is closed to new replies.