Shell的异步执行处理
Declare Function GetExitCodeProcess Lib ″kernel32″ Alias″GetExitCodeProcess″ (ByVal hProcess As Long, lpExitCode As Long) As Long
Declare Function OpenProcess Lib ″kernel32″ Alias ″OpenProcess″(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Const Process_Query_Information = &H400
Public Const Still_Active = &H103
Dim strWinDir As String
Dim pidNotepad As Long
Dim hProcess As Long
……
strWinDir = Environ(″windir″)
pidNotepad = Shell(strWinDir & ″\notepad.exe″, vbNormalFocus)
hProcess = OpenProcess(Process_Query_Information, False,pidNotepad)
Do GetExitCodeProcess hProcess, lngexitcode
Do Events
Loop While lngexitcode = Still_Active
……
以上实例的运行结果是,程序循环直到记事本程序退出,才会继续运行下面的VB程序,其中,strWinDir =Environ(″windir″)语句是通过环境变量获得当前系统的Window目录。这样就很好地解决了Shell语句的异步执行问题。