现有代码:
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可以使用。