View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Taskmgr from VBA


Well it looks like "trickery" to me...

'------------------------------
'From... Ivan F Moala
' 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
'--------------------------------------------


"Gary's Student" wrote in
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