pID=Shell("a.exe",vbhide)
用什么方法检查出这运行完毕后pID为0
while pID>0 
pID=???(就这儿,我忘记了是个什么api函数的)
...wend谢谢朋友提示一点

解决方案 »

  1.   

    你是想等程序执行完成后再检查执行是否成功,是吧?这个要用API的,具体的我也不记得了.
    明天去帮你查一下,如果你不着急的话.
      

  2.   

    用API函数实现的例子:Private Declare Function WaitForSingleObject Lib "kernel32" _
       (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As LongPrivate 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 LongPrivate Const INFINITE = -1&
    Private Const SYNCHRONIZE = &H100000Private Sub Command1_Click()
        Dim iTask As Long, ret As Long, pHandle As Long
        iTask = Shell("notepad.exe", vbNormalFocus)
        pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
        ret = WaitForSingleObject(pHandle, INFINITE)
        ret = CloseHandle(pHandle)
    End Sub
      

  3.   

    你好,谢谢你的回复,zjcxc
    这段waitforsingle运行时主程序会没响应,我是想如贴子所说
    用do...loop 检查退出,我想这样,您有好方法吗
      

  4.   

    Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongFunction IsRunning(ByVal ProgramID) As Boolean
    Dim hProgram As Long
    hProgram = OpenProcess(0, False, ProgramID)
    If Not hProgram = 0 Then
        IsRunning = True
    Else
        IsRunning = False
    End If
    CloseHandle hProgram
    End Function