SunQuest
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 1st, 2003, 08:28 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Finding all processes running on a machine

Ok, I'm having a major brainfart because I should know this but for the life of me cannot remember it. What I need to do is to get a list of handles of all processes running on the machine. I know it will take an API call, but for the life of me I don't know what it is and am having problems finding it. Anyone know?

Reply With Quote
  #2  
Old July 1st, 2003, 02:01 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
Onslaught I am sure you have found it by now but just in case here you go.
http://www.mentalis.org/apilist/EnumProcesses.shtml

Reply With Quote
  #3  
Old July 1st, 2003, 02:16 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Thanks for the link victorpendleton.

Reply With Quote
  #4  
Old July 2nd, 2003, 11:27 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Ok, this leads me to another question which I find myself pondering on. How do I get the process handle of the application that I am currently in? I know one easy solution would be to cycle through the processlist by name and get it by the application's name, but I cannot do that in this instance because there can be the possibility of multiple instances of this one application running at once.

Let me break it down and give a little history of what is going on here. I am writing a suite of applications, one of which is an activex applications that will communicate with another computer on a wan via dcom. There will be multiple computers that run this component. It will start out at around 15 computers, but will greatly increase to 200 or so after a couple of months. When an instance of this application starts up, it creates a log file with some vital information of what it is doing just in case the application dies or the server dies or anything bad happens and causes the process not to be completed. One of the other applications in the suite will watch for the activex application. It will also look at the log files that have been written. If there is a log file out there but not an corresponding application then I will launch a third application that starts up a local instance of the activex application and finishes the process.

So, in the activex application I must write out that instance's process handle so that it can be compared with the list of current processes running. I thought that maybe App.hInstance might be what I need, but this is not the case.

Any ideas on how I could solve this delima?

Reply With Quote
  #5  
Old July 9th, 2003, 11:20 PM
gthomso1 gthomso1 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 gthomso1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

Try this one


Public Function GetProcessHandle(strComputer As String) As Long
Dim ObjProcessSet As Object
Dim ObjThreadSet As Object
Dim objThread As Object
Dim objProcess As Object

'Query the minmgmts to get the process id from the threadID Should only be one value
Set ObjThreadSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery("Select * FROM Win32_PerfRawData_PerfProc_Thread WHERE IDThread=" & CStr(App.ThreadID))

For Each objThread In ObjThreadSet
'Now Get the Handle for the process corresponding to this thread
Set ObjProcessSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery("Select * FROM Win32_Process WHERE ProcessID=" & objThread.Properties_("IDProcess"))
For Each objProcess In ObjProcessSet
'Return the Handle for this process
GetProcessHandle = objProcess.Handle
Next
Next

GoSub Cleanup
Exit Function

Cleanup:
Set objProcess = Nothing
Set ObjProcessSet = Nothing
Set objThread = Nothing
Set ObjThreadSet = Nothing
Return

End Function

Reply With Quote
  #6  
Old July 10th, 2003, 07:45 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Thanks for the post gthomso1, I did however already solve this problem with the help of the link that victor posted and the help of some of our members through the C/C++ board.

To get the process id of the application itself you can use:
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long

Reply With Quote
  #7  
Old July 10th, 2003, 07:37 PM
gthomso1 gthomso1 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 gthomso1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
No problem I though there would have to be a more elegant way of doing it

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Finding all processes running on a machine


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway