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 Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredaccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Const INFINITE = -1& Private Const SYNCHRONIZE = &H100000
Private Sub Command1_Click() Dim i As Long Dim r As Long Dim p As Long i = Shell("notepad.exe", vbNormalFocus) p = OpenProcess(SYNCHRONIZE, False, i) r = WaitForSingleObject(p, INFINITE) r = CloseHandle(p) MsgBox "记事本已经关闭" End Sub