I want to use the API OpenProcess to get the handle of an external processs eg:- calc.exe
But i dont know how to get IDProcess(process identifier) of the process i am trying to get
handle so can any one please tell me how can i get th process id.

Also is it possible to terminate any open process from my application using TerminateProcess ??

Thankx in advance.
Posted on 2003-04-21 05:32:38 by telophase
Also is it possible to terminate any open process from my application using TerminateProcess ??
Yes, it is possible (but not nice) to end any regular app this way. You will not be able to kill the process though if it is a service or a system process.
Posted on 2003-04-21 06:55:13 by sluggy
I know 2 ways in getting the process ID of a program.

1. If the process has a window (calc.exe for example) you can do

invoke FindWindow, NULL, SADD("Calculator")
.if eax != NULL
invoke GetWindowThreadProcessId, eax, ADDR dwProcID
.endif

2. You can use CreateToolhelp32Snapshot for windows other than NT
(for NT, you can use PSAPI api EnumProcesses)

pe PROCESSENTRY32 <>

invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
.if eax != -1
mov hToolHelp, eax
invoke Process32First, hToolHelp, ADDR pe
.while TRUE

; you can now process the ID in pe.th32ProcessID

invoke Process32Next, hToolHelp, ADDR pe
.endw
invoke CloseHandle, hToolHelp
.endif

Maybe there are other ways of getting the process ID.

Hope this will help you
Posted on 2003-04-21 22:27:48 by rxbagain
Its has helped me.....a lot
Bye:grin:
Posted on 2003-04-22 00:03:31 by telophase