封装shell命令,使程序执行shell命令时等待shell关闭继续执行
Option Explicit
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 Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Const PROCESS_QUERY_INFORMATION = &H400
Const STILL_ALIVE = &H103
Public Sub WaitForSell(ByVal Pid As Long)
Dim HProcess, ExitCode As Long
HProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, Pid)
Do
Call GetExitCodeProcess(HProcess, ExitCode)
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(HProcess)
End Sub
Public Sub MyShell(ByVal PathName As String, Optional WindowStyle As VbAppWinStyle = vbNormalFocus)
WaitForSell Shell(PathName, WindowStyle)
End Sub