VB6 how to check if a Process ID has been terminated
<p>I need to know if a Process ID exists or not. Code so far:</p>

<pre><code>Option Explicit

Dim WshShell As Object
Dim EngineRun As Object

Sub main()

Set WshShell = CreateObject("WScript.Shell")
Set EngineRun = WshShell.Exec("notepad.exe")

MsgBox EngineRun.ProcessID

If EngineRun.ProcessID = True Then
    WshShell.run "TASKKILL /F /IM " &amp; EngineRun.ProcessID, , True
    MsgBox EngineRun.ProcessID &amp; (" terminated")
Else
    MsgBox EngineRun.ProcessID &amp; (" does not exist")
End If
End Sub
</code></pre>

<p>If I take out the "If" statement and have it open Notepad and show a MsgBox with the Process ID, it will then successfully kill Notepad when I click OK to the MsgBox</p>

<p>But with the "If" statement, it will show the " does not exist" MsgBox whether notepad is open or not. If it is open, it will successfully kill it, then show the " does not exist" MsgBox, instead of the " terminated" MsgBox.</p>

<p>Any ideas are very much appreciated!</p>