title: Run external application Modally in vb6?
body: <p>I was wondering about how to run external applications using Visual Basic 6.0. Running the application is not the problem, my problem is that I want to run the external application in a Modal way, that is, my application is inactive while the external application is running.</p>
  <pre><code>Option Explicit
  
  Private Declare Function OpenProcess Lib &quot;kernel32&quot; (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  Private Declare Function WaitForSingleObject Lib &quot;kernel32&quot; (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  Private Declare Function CloseHandle Lib &quot;kernel32&quot; (ByVal hObject As Long) As Long
  Private Const SYNCHRONIZE = &amp;H100000
  Private Const INFINITE = &amp;HFFFF
  Private Const WAIT_OBJECT_0 = 0
  Private Const WAIT_TIMEOUT = &amp;H102
  
  Private Sub Form_click()
  Dim llngProcID As Long
  Dim llngWinHwnd As Long
  Dim llngRetVal As Long
  
  llngProcID = Shell(&quot;c:\windows\system32\notepad.exe&quot;, vbNormalFocus)
  
  If llngProcID &lt;&gt; 0 Then
  
  llngWinHwnd = OpenProcess(SYNCHRONIZE, 0, llngProcID)
  DoEvents
  If llngWinHwnd &lt;&gt; 0 Then
  llngRetVal = WaitForSingleObject(llngWinHwnd, INFINITE)
  CloseHandle (llngWinHwnd)
  End If
  End If
  MsgBox &quot;Finished&quot;
  End Sub
  </code></pre>
  <p>This code solves me, but the way in which it blocks the vb6 application leaving it in &quot;Not Responding&quot; is not very pleasant, if anyone had any other way to do this, I would appreciate it.</p>