用 shell 执行 winrar的解压命令,如何知道解压已经完成。? 如果不等解压完成,往下运行会报错!郁闷中

解决方案 »

  1.   

    方法一:用FindWindow查找窗口
    方法二:得到命令行的返回信息
    方法三:(没有测试)
         Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
         Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Sub Command1_Click()
         Dim X
         Me.Caption = "开始运行"
         X = Shell("NotePad.EXE", 1)
         While IsRunning(X)
         DoEvents
         Wend
         Me.Caption = "结束运行"
    End Sub     Function IsRunning(ByVal ProgramID) As Boolean ' 传入进程标识ID
         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
      

  2.   

    用 shell 执行 winrar的解压命令 ....在解压完成的最后 你可以在调用一下你 的 VB程序 也就是 发送SHELL的程序  程序和程序本身之间可以使用DDE通信
      

  3.   

    http://www.chenoe.com/blog/article.asp?id=2017
      

  4.   

    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 Long
    Private Const PROCESS_QUERY_INFORMATION = &H400
    Private Const STILL_ACTIVE = &H103
    Dim strWinDir As String
    Dim pidNotepad As Long
    Dim hProcess As LongPrivate Sub Command1_Click()
        Dim lngExitCode As Long
        strWinDir = Environ("windir")
        pidNotepad = Shell(strWinDir & "\notepad.exe", vbNormalFocus)
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, pidNotepad)
        Do
            GetExitCodeProcess hProcess, lngExitCode
            DoEvents
        Loop While lngExitCode = STILL_ACTIVE
        MsgBox "Hello"
    End Sub
    以上代码就可以判断外部程序是否运行完,在窗体上画一个按钮试下。