VB是异步运行模式,需要用API达到同步运行的效果,这个已经在百度发过贴了,自己要多搜搜,给你个函数
'在标准模块中写入下列代码
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 RunProgram(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了,只需要用RunProgram 你的程序名
pid = Shell("C:\haha.bat", vbNormalFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
ExitEvent = WaitForSingleObject(hProcess, INFINITE)
Call CloseHandle(hProcess)
这些函数都到api查看器里找,都是标准api
额~~你是要转换成VB代码?