Taskmgr from VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I can activate taskmgr from a macro by

SHELL("c:\windows\system32\taskmgr.exe")

How can I access the displayed process information, i.e. process name and
PID, or get taskmgr to copy this information to a text file?
 
Perhaps someone will prove me wrong, but I think you would need some
sophisticated API trickery to do this.
 
Well it looks like "trickery" to me...

'------------------------------
'From... Ivan F Moala (e-mail address removed)
' public.excel.programming - March 20, 2004
'With some minor changes by
Jim Cone - San Francisco, USA
'----------------------

'WinXp / Xl2003
'// WMI String Constants
Private Const strWmgt As String = "winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2"
Private Const strWmiQ As String = "Select * from Win32_Process"

Sub OwnerOfProcesses()
Dim objWMIService As Object
Dim colProcessList As Object
Dim objProcess As Object
Dim strNameOfUser As Variant 'JBC
Dim strUserDomain As Variant 'JBC
Dim colProperties As String
Dim MyList() As Variant 'JBC
Dim x As Long 'JBC

Set objWMIService = GetObject(strWmgt)
Set colProcessList = objWMIService.ExecQuery(strWmiQ)

x = colProcessList.Count
ReDim MyList(0 To (x - 1), 0 To 3) 'JBC
x = 0

For Each objProcess In colProcessList
colProperties = objProcess.GetOwner(strNameOfUser, strUserDomain)
MyList(x, 0) = objProcess.Name
MyList(x, 1) = strUserDomain
MyList(x, 2) = strNameOfUser
MyList(x, 3) = objProcess.Handle
x = x + 1
Next

With Range("A1:D1")
.Value = Array("Process", "Domain", "User", "PID") 'JBC
.Font.Bold = True
End With
Range("A2").Resize(x, 4).Value = MyList 'JBC
Columns("A:D").AutoFit 'JBC
MsgBox "Processes: " & x

Set objWMIService = Nothing 'JBC
Set colProcessList = Nothing 'JBC
Set objProcess = Nothing 'JBC
End Sub
'--------------------------------------------


message I can activate taskmgr from a macro by
SHELL("c:\windows\system32\taskmgr.exe")
How can I access the displayed process information, i.e. process name and
PID, or get taskmgr to copy this information to a text file?
Gary's Student
 
Thanks for your help Vasant. I'll give your reference a try. If I can get
to a working API, then this will give me all that I need.

Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

TASKLIST.EXe vs TASKMGR 15
Taskmgr prob 1
Winows Cannot Find Task Manager 3
taskmgr problem! 2
problem with taskmgr display 2
taskmgr please help! 3
Missing taskmgr tray icon 6
lost buttons in taskmgr 3

Back
Top