Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle 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
Public Const PROCESS_QUERY_INFORMATION = &H400
Sub Command1_Click()
RunShell "c:\windows\notepad.exe"
End Sub
Private Sub RunShell (cmdline$)
Dim hProcess As Long
Dim ProcessId As Long
Dim exitCode As Long
ProcessId& = Shell(cmdline$, 1)
hProcess& = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId&)
Do
Call GetExitCodeProcess(hProcess&, exitCode&)
DoEvents
Loop While exitCode& > 0
MsgBox "The Shelled process " & cmdline$ & " has ended."
End Sub
http://www.experts-exchange.com/Programming/Langua ges/Visual_Basic/Q_10189013.html