Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1475

Here's how to make VB6 execute a program and then wait for it to close.

$
0
0
It's a VB6 sub called RunAndWait.
Code:

Private Const SYNCHRONIZE As Long = &H100000

Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long


Public Sub RunAndWait(ByVal FileName As String, Optional ByVal Args As String, Optional ByVal WindowStyle As VbAppWinStyle = vbNormalFocus)
Dim ProcID As Long
Dim hProc As Long
ProcID = Shell("""" & FileName & """ " & Args, WindowStyle)
hProc = OpenProcess(SYNCHRONIZE, 0, ProcID)
WaitForSingleObject hProc, -1
CloseHandle hProc
End Sub

Just paste this code into a module and you will be able to call it from anywhere in your program.

Viewing all articles
Browse latest Browse all 1475

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>