Module1.bas
-----------

Attribute VB_Name = "Module1"

Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Const PROCESS_INFO = &H400
Private Const STILL_RUNNING = &H103&

Public Function GetStringFromPtrW(ByVal ptr As Long) As String
  GetStringFromPtrW = String$(apiLStrLenW(ptr), 0)
  apiLStrCopyW StrPtr(GetStringFromPtrW), ptr
End Function

Public Sub RunShell(exe_and_batchstring As String)

    Dim hProcess As Long
    Dim ProcessId As Long
    Dim exitCode As Long
    Dim StrExitCode As String

    ProcessId = Shell(exe_and_batchstring, 1)
    hProcess = OpenProcess(PROCESS_INFO, False, ProcessId)

    Do
        Call GetExitCodeProcess(hProcess, exitCode)
        DoEvents
    Loop While exitCode = STILL_RUNNING
    StrExitCode = exitCode
    
    Call CloseHandle(hProcess)
    Form1.txtResult.Text = StrExitCode ' Show the exitcode on the form ...
    
'   MsgBox exe_and_batchstring & " ... ends with exitcode: " & StrExitCode

End Sub

frmTest.frm
-----------

VERSION 5.00
Begin VB.Form Form1 
   ...
   Begin VB.TextBox txtbatch 
      Height          =   375
      Left            =   1680
      TabIndex        =   3
      Text            =   """c:\temp\form.pdf"" 1"
      Top             =   600
      Width           =   6015
   End
   ...
   Begin VB.TextBox txtexe 
      Height          =   375
      Left            =   1680
      TabIndex        =   1
      Text            =   """c:\temp\unlock_ald.exe"" "
      Top             =   120
      Width           =   6015
   End
   Begin VB.CommandButton cmdFunk 
      Caption         =   "Starting the process ... and wait for the result"
      ...
   End
   ...
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cmdFunk_Click()

    RunShell txtexe.Text & " " & txtbatch.Text

End Sub

