VB等待进程结束

前端之家收集整理的这篇文章主要介绍了VB等待进程结束前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

VB运行EXE程序,并等待其运行结束

参考:https://blog.csdn.net/useway/article/details/5494084

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 OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long,ByVal bInheritHandle As Long,ByVal dwProcessId As Long) As Long
Private Sub Command1_Click()
    Dim i As Long
    Dim r As Long
    Dim p As Long
    i = Shell("NOTEPAD.EXE",vbNormalFocus)
    p = OpenProcess(&H100000,False,i)
    r = WaitForSingleObject(p,-1)
    r = CloseHandle(p)
    MsgBox "记事本已经关闭"
End Sub

VB运行批处理文件,并等待其运行结束

参考:http://blog.sina.com.cn/s/blog_7a44d6090100xdvf.html

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long,ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long,lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Command1_Click()
    Dim pid As Long
    Dim ExitCode as Long
    pid = Shell("c:\a.bat",vbNormalFocus)
    hProcess = OpenProcess(&H400,0,pid)
    Do
        Call GetExitCodeProcess(hProcess,ExitCode)
        DoEvents
    Loop While ExitCode = &H103
    Call CloseHandle(hProcess)
    MsgBox ("运行结束")
End Sub
原文链接:/vb/802167.html

猜你在找的VB相关文章