title: How to get Windows application process mainwindowtitle and window status properties using Excel VBA?
body: <p>Need help getting mainwindowtitle or window status properties using <strong>Excel VBA script</strong>?</p>
  
  <p>On my windows machine I have two processes running with same name e.g. xyz.exe.</p>
  
  <p>One of them has windows application and the other is kind of helper or background process. I want to find out which one is the windows application process using mainwindowtitle or window status properties. </p>
  
  <p>The reason I chose these properties because background process has no mainwindowtitle and window status is null. Below is the process explorer screen shot showing the two processes.</p>
  
  <p><a href="https://i.stack.imgur.com/SBpbr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SBpbr.jpg" alt="enter image description here"></a></p>
  
  <p>Using WMI Tasks for Scripts and Applications I can easily find out the process ids but I am not able to figure out how to get the mainwindowtitle or window status property.</p>
  
  <pre><code>Private Sub getP()       
      strComputer = "."
      sExeName = "XYZ.exe"
  
      Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\CIMV2")
      Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process 
      WHERE Name = '" &amp; sExeName &amp; "'", , 48)
  
      For Each objItem In colItems
        Debug.Print "ProcessId: " &amp; objItem.ProcessId
      Next
  End Sub
  </code></pre>