ProgramID = Shell(lpCmdLine, nCmdShow)
    hProgram = OpenProcess(SYNCHRONIZE, False, ProgramID)
    
    If hProgram <> 0 Then
        Call WaitForSingleObject(hProgram, WAIT_TIMEOUT)
        Call CloseHandle(hProgram)
    End If

解决方案 »

  1.   

    to: zyl910(910:分儿,我来了!) 
    给出的代码运行有错,有几个函数未定义,能否将代码写全一点,谢谢!
      

  2.   

    Shell函数就可以拉,你要异步调用,就情显示获得其返回值吧!
    如:  
       dim a as integer  
       a=shell("C:\format C:/q/u")
      

  3.   

    to timiil(小华) :
    我已试过此方法,结果不行!
      

  4.   

    Public Function ShellAndWait(ByVal vCommandLine As String) As Boolean
       Dim o_ProcName As PROCESS_INFORMATION
       Dim o_NameStart As STARTUPINFO
       Dim o_ProcessHandle As Long
       
       o_NameStart.cb = Len(o_NameStart)
       o_NameStart.wShowWindow = 0
       o_ProcessHandle = CreateProcessA(0&, _
                                        vCommandLine, _
                                        0&, _
                                        0&, _
                                        1&, _
                                        NORMAL_PRIORITY_CLASS Or CREATE_NO_WINDOW, _
                                        0&, _
                                        0&, _
                                        o_NameStart, _
                                        o_ProcName)
       o_ProcessHandle = WaitForSingleObject(o_ProcName.hProcess, INFINITE)
       o_ProcessHandle = CloseHandle(o_ProcName.hProcess)
    End Function
      

  5.   

    Public Type PROCESS_INFORMATION
       hProcess    As Long
       hThread     As Long
       dwProcessID As Long
       dwThreadID  As Long
    End Type
    Public Type STARTUPINFO
       cb                As Long
       lpReserved        As String
       lpDesktop         As String
       lpTitle           As String
       dwX               As Long
       dwY               As Long
       dwXSize           As Long
       dwYSize           As Long
       dwXCountChars     As Long
       dwYCountChars     As Long
       dwFillAttribute   As Long
       dwFlags           As Long
       wShowWindow       As Integer
       cbReserved2       As Integer
       lpReserved2       As Long
       hStdInput         As Long
       hStdOutput        As Long
       hStdError         As Long
    End Type
    Public Const NORMAL_PRIORITY_CLASS  As Long = &H20&
    Public Const CREATE_NO_WINDOW       As Long = &H8000000
    Public Const INFINITE = -1&
    Public Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Boolean
    Public Declare Function WaitForSingleObject _
                   Lib "kernel32" (ByVal hHandle As Long, _
                   ByVal dwMilliseconds As Long) As Long
    Public Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, _
                                                    ByVal lpCommandLine As String, _
                                                    ByVal lpProcessAttributes As Long, _
                                                    ByVal lpThreadAttributes As Long, _
                                                    ByVal bInheritHandles As Long, _
                                                    ByVal dwCreationFlags As Long, _
                                                    ByVal lpEnvironment As Long, _
                                                    ByVal lpCurrentDirectory As Long, _
                                                    lpStartupInfo As STARTUPINFO, _
                                                    lpProcessInformation As PROCESS_INFORMATION) As Long