关于VB的Shell同步执行问题
又看到有朋友遇到这个问题,公布一个解决方法'标准模块中
Public Const SYNCHRONIZE = &H100000
Public Const INFINITE = &HFFFFFFFF
Public Const WAIT_TIMEOUT = &H102&
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
sub RunExe(FileName as string)
Dim pId As Long, pHnd As Long, ret
pId = Shell(FileName, vbNormalFocus)
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
If pHnd <> 0 Then
Do
ret = WaitForSingleObject(pHnd, 0)
DoEvents
Loop While ret = WAIT_TIMEOUT
CloseHandle pHnd
End If
End Sub
'遇到要用Shell调用程序时换用Runexe函数执行