Well, I have an answer to my own question but I'm still a little confused:(
The snippet of code below will get handles and PIDs for all the running programs (at least that is what I think they are). What I find confusing is that some of the handles look like PIDs (when checked in the Windows Task Managed) those handles that look like PIDs get 0 when I ask for its PID. Does anyone know enough about C and Windows to tell me what's going on here?
| pf osProcessesArray osProcessCountReturned osProcesses osProcessCount result pIds |
osProcessesArray := ByteArray new: 1000.
osProcessCountReturned := ByteArray new: 4.
pf := PlatformFunction fromArray: #('C' 'EnumProcesses' nil 'Psapi.dll' #(#pointer #int32 #pointer) #bool).
result := pf callWith: osProcessesArray with: osProcessesArray size with: osProcessCountReturned.
result ifTrue: [
osProcessCount := (osProcessCountReturned uint32At: 0) // 4.
osProcesses := Array new: osProcessCount.
pIds := Array new: osProcessCount.
1 to: osProcessCount do: [:i | | offset h pId |
offset := (i - 1) * 4.
h := OSHwnd immediate: (osProcessesArray uint32At: offset).
h notNull ifTrue: [
osProcesses at: i put: h.
pId := ByteArray new: 4.
h getWindowThreadProcessId: pId.
pIds at: i put: (pId uint32At: 0).
].
].
].
osProcesses inspect.
pIds inspect.
Bigger picture. I am trying to find the handle of one program (maybe two) in-particular. So, I need to find the name of the Exe that is running from the handle. When I find the program I want I then need to get its PID and other info like how much memory and CPU it is using.
Lou