|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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?
|
|
#2
|
|||
|
|||
|
Onslaught I am sure you have found it by now but just in case here you go.
http://www.mentalis.org/apilist/EnumProcesses.shtml |
|
#3
|
||||
|
||||
|
Thanks for the link victorpendleton.
![]() |
|
#4
|
||||
|
||||
|
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? |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
No problem I though there would have to be a more elegant way of doing it
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Finding all processes running on a machine |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|