抱歉,这已经回答了,我找不到。我需要从 vb6 应用程序启动外部进程并等待该进程完成,然后再继续。很简单。但是,我需要依次启动的进程会启动一个子进程然后退出。我需要等待子进程完成(和其他子进程)
现有代码:
Private Const WAIT_INFINITE = -1&
Private Const SYNCHRONIZE = &H100000
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Public Sub ShellProcess(strProcess As String, Optional blnWait As Boolean = False)
Dim hProc As Long
Dim taskId As Long
Dim cmdline As String
cmdline = strProcess
taskId = Shell(cmdline, vbNormalFocus)
If blnWait = True Then
hProc = OpenProcess(SYNCHRONIZE, True, taskId)
Call WaitForSingleObject(hProc, WAIT_INFINITE)
CloseHandle hProc
End If
MsgBox "The shelled app has ended."
End Sub
我曾经设法在 c# 中做到这一点,但现在只有 vb6 可以使用。