vb如何监视一个进程什么时候结束,进程是一个没有窗口的。
比如一个dos 复制命令 xcopy
当一个文件复制结束后,xcopy.exe 这个进程也就结束了,怎样用vb 来监视它什么时候结束的。

解决方案 »

  1.   

    OpenProcess()
    WaitForSingleObject()
    OK?
      

  2.   

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    '判断程序是否运行完成
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode 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 PROCESS_QUERY_INFORMATION = &H400
    Private Const STILL_ACTIVE = &H103
     Dim lngExitCode3 As Long '用于判断程序是否运行完成
                                               CmdRasdial = Shell("Rasdial.exe  " & test& "  " & VPNLoginName & "  " & VPNPassword, vbHide)
                                               hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, CmdRasdial) '进程处理
                                               link.Picture = TempLinkDownPic '
                                               link.Enabled = False
                                               winexit.Enabled = False  '当程序正在建立连接时候不能关闭连接
                                               winexit.Picture = TempExitDownPic
                                               Infmessage.Caption = LinkInf
                                               Do '                                           GetExitCodeProcess hProcess, lngExitCode3
                                               DoEvents
                                               Loop While lngExitCode3 = STILL_ACTIVE