加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB等待进程结束

发布时间:2020-12-17 07:29:06 所属栏目:百科 来源:网络整理
导读: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 Funct

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读