VBA Get program names and task IDs of running processes
How to get program names and task IDs of running processes.
returns the task id of the initiated process. Likewise, I would like to get the task id and name of the processes that are already running and not created by the macro. I found some code that returns program names, but the output is missing information about task IDs:
Sub Test_AllRunningApps() Dim apps() As Variant = AllRunningApps 1).Value2 = WorksheetFunction.Transpose(apps) :A").Columns.AutoFit End Sub to: http://msdn.microsoft.com/en-us/library/aa393618%28VS.85%29.aspx Public Function AllRunningApps() As Variant Dim strComputer As String Dim objServices As Object, objProcessSet As Object, Process As Object Dim oDic As Object, a() As Variant Set oDic = CreateObject("Scripting.Dictionary") strComputer = "." Set objServices = GetObject("winmgmts:\\" _ strComputer & "\root\CIMV2") Set objProcessSet = objServices.ExecQuery _ Name FROM Win32_Process", , 48) For Each Process In objProcessSet If Not oDic.exists(Process.Name) Then oDic.Add Process.Name, Process.Name Next = oDic.keys Set objProcessSet = Nothing Set oDic = Nothing AllRunningApps = a() End Function
source to share