ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Taskmgr from VBA (https://www.excelbanter.com/excel-programming/331532-taskmgr-vba.html)

Gary's Student

Taskmgr from VBA
 
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

Vasant Nanavati

Taskmgr from VBA
 
Perhaps someone will prove me wrong, but I think you would need some
sophisticated API trickery to do this.

--

Vasant


"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




Vasant Nanavati

Taskmgr from VBA
 
If you're really ambitious, you can try and adapt this for your needs (I
tested it and it works but you may have to tweak it to get all the
information you want):

How to list running processes
http://support.microsoft.com/default...b;en-us;187913

--

Vasant

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Perhaps someone will prove me wrong, but I think you would need some
sophisticated API trickery to do this.

--

Vasant


"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






Jim Cone

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

Gary's Student

Taskmgr from VBA
 
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
--
Gary's Student


"Vasant Nanavati" wrote:

If you're really ambitious, you can try and adapt this for your needs (I
tested it and it works but you may have to tweak it to get all the
information you want):

How to list running processes
http://support.microsoft.com/default...b;en-us;187913

--

Vasant

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Perhaps someone will prove me wrong, but I think you would need some
sophisticated API trickery to do this.

--

Vasant


"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







Vasant Nanavati

Taskmgr from VBA
 
Now that is pretty darned neat ... kudos to Ivan!

--

Vasant


"Jim Cone" wrote in message
...

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




Gary's Student

Taskmgr from VBA
 
Thank you both very much !!
--
Gary's Student


"Vasant Nanavati" wrote:

Now that is pretty darned neat ... kudos to Ivan!

--

Vasant


"Jim Cone" wrote in message
...

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





RB Smissaert

Taskmgr from VBA
 
You need Edanmo's task scheduler.
Have a look at this website:
http://www.mvps.org/emorcillo/en/code/vb6/index.shtml

Go to: Using the Task Scheduler

This is a VB dll file that makes all the properties and methods of the task
scheduler available in VBA. I am using this and it works very well.

RBS


"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




All times are GMT +1. The time now is 12:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com