在VB中怎么能完整的执行一个EXE文件???
这里我指的是完整执行
我用过SHELL,ShellExecute....可都不能完整的执行
我的程序调用了很多外部文件...用上面的函数总是不能完整的执行...
郁闷ING
帮助..谢谢

解决方案 »

  1.   

    完整就是完整的执行备.
    用SHELL,ShellExecute函数总是不能完整的执行...
    我有很多外部文件.好象不读似的
    哎...比较难叙述.
    反正不能正常执行
    直接去执行,或在DOS下执行就OK....(应该不少人碰到过吧)
    帮忙
      

  2.   

    楼主是执行 shell 后没有等待吧?
    shell 后的语名不会等目标程序的,调用后直接就执行 shell 的下一句了。
    要在vb程序做一定的处理,让它等待 shell 的调用者完成。
    要用到 api
      

  3.   

    to  fxy_2002(阿勇)
    等待了.完全等待了..
      

  4.   

    to thirdapple(.:RNPA:.陨落雕-鍾意吊帶MM) 
    和SHELL一起用了.
    哎.正郁闷呢
      

  5.   

    start /wait app.exe
    可以实现等待app执行完毕在执行其他命令,可以写一段批处理文件测试一下:start /wait cmd
    echo finish
      

  6.   

    '声明:
    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 Const SW_SHOW = 5'调用
    Call ShellExecute(App.hInstance, "open", "c:\test.exe", vbNullString, vbNullString, SW_SHOW)我曾经遇到过一种情况,上面函数的最后一个参数如果是0(也可能是1),应用程序的有些模块就无法加载,不知楼主的情况是否这样。
      

  7.   

    to kissoflife(明月高楼休独倚,酒入愁肠,化作相思泪!)我用了和你一样的方法.最后的参数是5.可还是不能正常启动程序...
    不知道是为什么!
    急招牛人啊
      

  8.   

    用API Guide搜索WaitForSingleObject有个这方面例子的
      

  9.   

    等待过了.....
    可结果一样...晕死中在DOS下执行就很好....用批处理?那不是很晕!!
      

  10.   

    怎么看都看不懂……DOS?控制台吧,试试这样:
    Shell "cmd.exe /c 你的程序.exe"迷茫……
      

  11.   

    faint  我也看不懂!到底什么意思?什么叫完整执行?说具体点。如果是“执行程序并等待执行结束”的话,可以这样: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 Long
    Private Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" (lpInfo As Any) As LongPrivate Type SHELLEXECUTEINFO
        cbSize As Long
        fMask As Long
        hwnd As Long
        lpVerb As String
        lpFile As String
        lpParameters As String
        lpDirectory As String
        nShow As Long
        hInstApp As Long
     
        ' Optional members
        lpIDList As Long
        lpClass  As String
        hkeyClass As Long
        dwHotKey As Long
        hIcon_OR_Monitor As Long
        hProcess As Long
    End Type
    Private Sub Form_Load()
        
        Dim si As SHELLEXECUTEINFO
        si.cbSize = Len(si)
        
        si.lpVerb = "open"
        si.lpFile = "notepad.exe"
        si.lpParameters = ""
        si.lpDirectory = ""    si.nShow = 5     'SW_SHOW
        si.fMask = &H40  'SEE_MASK_NOCLOSEPROCESS
        
        ShellExecuteEx si
        
        If si.hProcess <> 0 Then
            WaitForSingleObject si.hProcess, &HFFFFFFFF  ' 无限等待, 直到程式结束
            CloseHandle si.hProcess
            MsgBox "程序运行完毕!"
        End If
    End Sub
      

  12.   

    API-Guide上面的例子
    'This program needs a common dialog box, named CDBox
    '  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
    '   and select Microsoft Common Dialog control)
    Const INFINITE = &HFFFF
    Const STARTF_USESHOWWINDOW = &H1
    Private Enum enSW
        SW_HIDE = 0
        SW_NORMAL = 1
        SW_MAXIMIZE = 3
        SW_MINIMIZE = 6
    End Enum
    Private Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessId As Long
        dwThreadId As Long
    End Type
    Private 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 Byte
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
    End Type
    Private Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
    End Type
    Private Enum enPriority_Class
        NORMAL_PRIORITY_CLASS = &H20
        IDLE_PRIORITY_CLASS = &H40
        HIGH_PRIORITY_CLASS = &H80
    End Enum
    Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Function SuperShell(ByVal App As String, ByVal WorkDir As String, dwMilliseconds As Long, ByVal start_size As enSW, ByVal Priority_Class As enPriority_Class) As Boolean
        Dim pclass As Long
        Dim sinfo As STARTUPINFO
        Dim pinfo As PROCESS_INFORMATION
        'Not used, but needed
        Dim sec1 As SECURITY_ATTRIBUTES
        Dim sec2 As SECURITY_ATTRIBUTES
        'Set the structure size
        sec1.nLength = Len(sec1)
        sec2.nLength = Len(sec2)
        sinfo.cb = Len(sinfo)
        'Set the flags
        sinfo.dwFlags = STARTF_USESHOWWINDOW
        'Set the window's startup position
        sinfo.wShowWindow = start_size
        'Set the priority class
        pclass = Priority_Class
        'Start the program
        If CreateProcess(vbNullString, App, sec1, sec2, False, pclass, _
        0&, WorkDir, sinfo, pinfo) Then
            'Wait
            WaitForSingleObject pinfo.hProcess, dwMilliseconds
            SuperShell = True
        Else
            SuperShell = False
        End If
    End Function
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'Set the dialog's title
        CDBox.DialogTitle = "Choose an EXEC-File ..."
        'Error when canceled
        CDBox.CancelError = True
        'Set the dialog's filter
        CDBox.Filter = "EXEC-Files (*.exe)|*.exe|All files (*.*)|*.*"
        'Show the 'Open File'-dialog
        CDBox.ShowOpen
        'Execute the program
        SuperShell CDBox.filename, Left$(CDBox.filename, Len(CDBox.filename) - Len(CDBox.FileTitle)), 0, SW_NORMAL, HIGH_PRIORITY_CLASS
        End
    End Sub
      

  13.   

    晕死...
    现在有SHELL也可以了!!!
    后面几位大哥的例子也试了.都好了
    可以前为什么不可以呢??!!!!
    以前我用shell,ShellExecute,WaitForSingleObject....
    可都不行啊...现在TNN的好了....郁闷!!!!!!!!!!!!!!!
      

  14.   

    啊!!!!!!!!!!!!!!!!
    啊!!!!!!!!!!!!!!!!!!!!!
    Private Sub Form_Load()
    Shell "c:\aa\TwoShow\Main.exe", vbMaximizedFocus
    End Sub
    同样一句话,写到2个不同的程序了,结果就不一样啊!!!!!!!
    1个能正常显示
    1个不能正常显示.....TNND,疯了!
      

  15.   

    和你一起晕,试着用CreateProcess吧。