Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

Get the Process ID from a handle

I while back I think Madshi wanted to know how to get the Process ID from a handle, see this link...

http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_10073493.html

This works well in 98, but not under XP (probably not NT and above)...  Is there a way of doing this for NT and above?

0
Chris Nillissen
Asked:
Chris Nillissen
1 Solution
 
MrGhostCommented:
check:
1 - Using the GetWindowThreadProcessId()
2 - Using the ToolHelp API
0
 
MadshiCommented:
Look on the net for NtQueryProcessInformation.
0
 
MartinVenterCommented:
Hi ChrisNillessen,

Dont know if your question has been answerd but here is my answer anyway.
Below is a function that uses GetWindowThreadProcessID like MrGhost suggested.

function GetProcID(Handle: THandle): THandle;
var
  ProcID: THandle;
begin
  GetWindowThreadProcessID(Handle, @ProcID);
  Result := ProcID;
end;

Regards,
Martin
0
 
CleanupPingCommented:
ChrisNillissen:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
MadshiCommented:
MrGhost and MartinVenter both misunderstood the question. They both explained how to get the process id from a window handle. But the question was how to get the process id from a process handle. This can be done only by using NtQueryInformationProcess, as I suggested.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now