Need help getting mainwindowtitle or window status properties using Excel VBA script?
On my windows machine I have two processes running with same name e.g. xyz.exe.
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.
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.
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.
Private Sub getP()
strComputer = "."
sExeName = "XYZ.exe"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process
WHERE Name = '" & sExeName & "'", , 48)
For Each objItem In colItems
Debug.Print "ProcessId: " & objItem.ProcessId
Next
End Sub
Based on what David mentioned in comment, try this: