-1

Possible Duplicate:
how to get process handle from process id?

Hello! How i can guaranteed get process handle by process id in windows OS. If exist methods block for my applications opportunity to get process handle by PID. For my application getting Process handle by PID is critical. If yes what this methods and how i can avoid this methods. Thanks!

Community
  • 1
  • 1
lebron2323
  • 990
  • 2
  • 14
  • 29
  • MSDN:OpenProcess. For anything more, please try to clarify the question. Sorry, I can't understand it. – atzz Mar 16 '11 at 15:33
  • "avoid this method" - The question is not clear to me: what do you want? Do you want to get the handle, or to prevent other processes from getting it? – Suma Mar 16 '11 at 15:38

2 Answers2

2

Even if you have a valid PID, you are not guaranteed to be able to get a handle to that process:

  • The process could terminate before your call to OpenProcess
  • You might not have the rights to open a handle to the process (Even running as admin with debug privileges, there are System/Anti-Virus/DRM processes you cannot access on NT6+, at least if you want PROCESS_ALL_ACCESS, you are pretty likely to get PROCESS_QUERY_LIMITED_INFORMATION access though)
Anders
  • 97,548
  • 12
  • 110
  • 164
0

Use OpenProcess.

Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589