我想等shell语句结束后再返回窗体.在这之前窗体锁死!我的代码为Private Declare Function WaitForSingleObject Lib _
  "kernel32" (ByValhHandle As Long, _
  ByValdwMilliseconds As Long) As Long
  
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFFPrivate Declare Function OpenProcess Lib "kernel32" _
  (ByValdwDesiredAccess As Long, _
  ByValbInheritHandle As Long, _
  ByValdwProcessId As Long) As LongPrivate Sub Command1_Click()
Dim hHandle As Long, pid As Long
txtStatus.Text = "Processing"
txtStatus.Refresh
pid = Shell("G:\a\pa\a.exe G:\a\a\*.abc", vbNormalFocus)If pid <> 0 Then
    hHandle = OpenProcess(SYNCHRONIZE, 0&, pid)
    Text1 = hHandle
    WaitForSingleObject hHandle, INFINITE
    txtStatus.Text = "Finished"
Else
    txtStatus.Text = "Error shelling "
End If
End Suba.exe 为dos命令程序.不知道为什么锁不住. 高人回复

解决方案 »

  1.   

    //pid = Shell("G:\a\pa\a.exe G:\a\a\*.abc", vbNormalFocus)
    改为:
    pid = Shell("cmd /c G:\a\pa\a.exe G:\a\a\*.abc", vbNormalFocus)试试
      

  2.   

    我没有你的dos程序,我用debug.exe作为演示:
    Option ExplicitPrivate Declare Function OpenProcess Lib "kernel32" _
       (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
        ByVal dwProcessId As Long) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" _
       (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" _
       (ByVal hObject As Long) As LongConst PROCESS_QUERY_INFORMATION = &H400
    Const SYNCHRONIZE = &H100000
    Const STILL_ALIVE = &H103
    Const INFINITE = &HFFFFPrivate ExitCode As LongPrivate isDone As Long
    Private Sub Command1_Click()
    Dim pid As Long
    Dim ExitEvent As Long
    Dim hProcess As Long
    pid = Shell("cmd /c e:\windows\system32\debug.exe", vbNormalFocus)
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION + SYNCHRONIZE, 0, pid)
    ExitEvent = WaitForSingleObject(hProcess, INFINITE)
    Call CloseHandle(hProcess)
    MsgBox "aaa"
    End Sub顺便问一下,你是什么操作系统,98的话:
    要将cmd改为command
      

  3.   

    用这个简单:Private Sub Command1_Click()
    Set wshl = CreateObject("wscript.Shell")
    wshl.Run "notepad.exe", 1, True
    MsgBox "AAA"
    End Sub