VB等待进程结束

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

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

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

Private@H_403_13@ Declare@H_403_13@ Function@H_403_13@ WaitForSingleObject Lib@H_403_13@ "@H_403_13@kernel32@H_403_13@"@H_403_13@ (ByVal@H_403_13@ hHandle As@H_403_13@ Long@H_403_13@,ByVal@H_403_13@ dwMilliseconds As@H_403_13@ Long@H_403_13@) As@H_403_13@ Long@H_403_13@
Private@H_403_13@ Declare@H_403_13@ Function@H_403_13@ CloseHandle Lib@H_403_13@ "@H_403_13@kernel32@H_403_13@"@H_403_13@ (ByVal@H_403_13@ hObject As@H_403_13@ Long@H_403_13@) As@H_403_13@ Long@H_403_13@
Private@H_403_13@ Declare@H_403_13@ Function@H_403_13@ OpenProcess Lib@H_403_13@ "@H_403_13@kernel32@H_403_13@"@H_403_13@ (ByVal@H_403_13@ dwDesiredAccess As@H_403_13@ Long@H_403_13@,ByVal@H_403_13@ bInheritHandle As@H_403_13@ Long@H_403_13@,ByVal@H_403_13@ dwProcessId As@H_403_13@ Long@H_403_13@) As@H_403_13@ Long@H_403_13@
Private@H_403_13@ Sub@H_403_13@ Command1_Click()
    @H_403_13@Dim@H_403_13@ i As@H_403_13@ Long@H_403_13@
    Dim@H_403_13@ r As@H_403_13@ Long@H_403_13@
    Dim@H_403_13@ p As@H_403_13@ Long@H_403_13@
    i @H_403_13@= Shell@H_403_13@("@H_403_13@NOTEPAD.EXE@H_403_13@"@H_403_13@,vbNormalFocus)
    p @H_403_13@= OpenProcess(&H100000,False@H_403_13@,i)
    r @H_403_13@= WaitForSingleObject(p,-1@H_403_13@)
    r @H_403_13@= CloseHandle(p)
    @H_403_13@MsgBox@H_403_13@ "@H_403_13@记事本已经关闭@H_403_13@"@H_403_13@
End Sub@H_403_13@

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

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

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

猜你在找的VB相关文章