Here is an example of how to obtain an exit code. It uses Notepad.exe in this sample. Both Notepad and the vb app are running on the same PC.
Copy the code below into a form module with a command button named Command1
Option Explicit
Const NORMAL_PRIORITY_CLASS As Long = &H20
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function CreateProcess& Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) 'As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function GetExitCodeProcess& Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long)
Private Sub Command1_Click()
Dim lProcess As Long
Dim StartInfo As STARTUPINFO
Dim ProcessInfo As PROCESS_INFORMATION
Dim lExitCode As Long
Dim iRetrievedProcessCode As Long
Const INFINITE = &HFFFF
lProcess = CreateProcess("C:\WINNT\Notepad.exe", vbNullString, 0, 0, True, NORMAL_PRIORITY_CLASS, ByVal 0&, vbNullString, StartInfo, ProcessInfo)
WaitForSingleObject ProcessInfo.hProcess, INFINITE ' INFINITE = wait for in milliseconds, waits forever inthis case
iRetrievedProcessCode = GetExitCodeProcess(ProcessInfo.hProcess, lExitCode)
If iRetrievedProcessCode <> 0 Then
MsgBox "Notepade was terminated" & vbCrLf & vbCrLf & "Exit Code = " & Format$(lExitCode)
Else
MsgBox "Could not obtain exit code. . . "
End If
End Sub