'下面是解决VB中异步执行的例子.Option Explicit' ShellWat sample by Matt Hart - [email protected] ' http://www.webczar.com/defcon/mh/vbhelp.html ' http://www.webczar.com/defcon/mh ' ' Shows how to shell to another program, and wait until it finishes ' before continuing.Private Declare Function WaitForSingleObject Lib "kernel32" _ (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32" _ (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As LongPrivate Const INFINITE = -1& Private Const SYNCHRONIZE = &H100000Private Sub Command1_Click() Dim iTask As Long, ret As Long, pHandle As Long iTask = Shell("notepad.exe", vbNormalFocus) pHandle = OpenProcess(SYNCHRONIZE, False, iTask) ret = WaitForSingleObject(pHandle, INFINITE) ret = CloseHandle(pHandle) End Sub
' http://www.webczar.com/defcon/mh/vbhelp.html
' http://www.webczar.com/defcon/mh
'
' Shows how to shell to another program, and wait until it finishes
' before continuing.Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As LongPrivate Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000Private Sub Command1_Click()
Dim iTask As Long, ret As Long, pHandle As Long
iTask = Shell("notepad.exe", vbNormalFocus)
pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
ret = WaitForSingleObject(pHandle, INFINITE)
ret = CloseHandle(pHandle)
End Sub