title: Setting external application focus
body: <p>In VB.NET, you can set focus to an external application using</p>
  
  <pre class="lang-vb.net prettyprint-override"><code>AppActivate("Windows Name")
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-vb.net prettyprint-override"><code>AppActivate(processID As Integer)
  </code></pre>
  
  <p>Now this works fine if you do for example:</p>
  
  <pre class="lang-vb.net prettyprint-override"><code>Dim intNotePad As Integer = Shell("C:\WINNT\Notepad.exe",
  AppWinStyle.MinimizedNoFocus)
  AppActivate(intNotePad)
  </code></pre>
  
  <p>But when I do:</p>
  
  <pre class="lang-vb.net prettyprint-override"><code>For Each theprocess As Process In processlist
      If InStr(theprocess.ProcessName, "DWG") Then
          strProcessList += String.Format("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id) + vbCrLf
          AppActivate(theprocess.ID)
      End If
  Next
  </code></pre>
  
  <p>then it doesn't find the window, even if it's open and even if it finds the window using the window title.</p>
  
  <p>But I need it by process ID.</p>
  
  <p>How can I do that?</p>
  
  <p>I need it to set focus on a 3rd party installer in a windows installer setup project.</p>