在VB4.0中好像用GetModuleUsage()就可以判断,但在6.0中好像没有这个函数了,
那位知道改如何判断用shell执行的程序是否结束,是不是在6.0中也有对应的一个函数?

解决方案 »

  1.   

    '以下例子演示如何打开一个应用程序并等待执行完毕,之后关闭自己。Private 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 LongDim pID As LongFunction StillRun(ByVal ProgramID) As Boolean
        Dim lHProgram As Long
        Dim lReturn As Long    hProgram = OpenProcess(0, False, ProgramID)
        If Not hProgram = 0 Then
            StillRun = True
        Else
            StillRun = False
        End If
        CloseHandle hProgram
    End FunctionPrivate Sub Form_Load()
        If Dir$("c:\windows\cdplayer.exe") <> "" Then
            Me.Show
            pID = Shell("c:\windows\cdplayer.exe")
            While StillRun(pID)
                DoEvents
            Wend
            End
        Else
            MsgBox "没有找到CD播放器"
            End
        End If
    End Sub
      

  2.   

    可以参考:
    Shell一个应用程序并等待该程序执行完毕后继续运行:
    http://www.xhstudio.net/show.asp?id=2177
    顺序调用多个可执行文件:
    http://www.china-askpro.com/msg1/qa21.shtml
    使用Shell指令具有Wait的功能:
    http://school.enet.com.cn/eschool/inforcenter/A20040324297013.html
      

  3.   

    谢谢kissoflife,我给据你的做法,稍加改动撮成功了,
    如下:
    在一般模块中:
    Public Const SYNCHRONIZE = &H100000
    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具体运用:
        Dim pID As Long, pHnd As Long ' 分别声明 Process Id 及 Process Handle 变数
        pID = Shell(App.Path + "\WENNER.exe", 1)
        II = MsgBox("     提示:正在运行,DOS窗口结束后按回车键 ...", 0, "    运行接地电阻计算程序")
        StillRun1 = True
        While StillRun1
            pHnd = OpenProcess(SYNCHRONIZE, 0, pID)
            If pHnd <> 0 Then
               StillRun1 = True
            Else
               StillRun1 = False
            End If
            CloseHandle pHnd
        Wend再次感谢