How to determine whether a process handle is of the current process?

Paul

I have a HANDLE to a process, which might, or might not, be the handle of the currently running process. The following is known about the handle object:

  1. The handle only has the PROCESS_TERMINATE access right.
  2. The handle is not a pseudo-handle, i.e. not the return value of GetCurrentProcess.

Is there a way to know whether the handle is of the current process?

I thought about using GetProcessId, but unfortunately it fails with an access denied error, because the handle doesn't have the PROCESS_QUERY_LIMITED_INFORMATION access right.

Harry Johnston

If you have sufficient access to the target process, you can create a new handle to it with the PROCESS_QUERY_LIMITED_INFORMATION access right by using DuplicateHandle(). You can then use this handle to get the process ID.

Unless your process modifies its own security permissions, it should always have (at least) PROCESS_QUERY_LIMITED_INFORMATION access to itself, so if duplicating the handle fails with an access denied error it is unlikely that the handle points to your process.

If you want to make absolutely certain, you can try opening a handle to your process by process ID - if that fails then someone is messing with the ACL and all bets are off. :-)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Determine whether the parent process is a terminal

From Dev

How to determine whether a process's privilege exists and its enabled/disabled?

From Dev

How to check whether a process is daemon or not?

From Dev

How can I determine if a process is a system process?

From Dev

How to get the process handle of an elevated process?

From Dev

How to determine whether a process is running or not and make use it to make a conditional shell script?

From Dev

How to determine if a process has GUI or not?

From Dev

Determine at runtime whether the "Visual Studio Hosting Process" is enabled?

From Dev

How to get file handle of a process?

From Dev

How to handle signal in foreground process?

From Dev

how to unshare network for current process

From Dev

How does the fork() know whether it is in child process and in parent process?

From Dev

Lua: how to check whether a process is running

From Dev

How to check whether the process was restarted by supervisor?

From Dev

How to know whether a process ended in JBPM

From Dev

How can I determine if process is user program or simply a process

From Dev

determine current process priority from within a running bash script

From Java

How to determine if a process runs inside lxc/Docker?

From Dev

How to determine there are no running jobs or consumer process exit

From Dev

How to determine the process responsible for an intermittent packet?

From Dev

How to determine which process owns a toplevel window?

From Dev

How to determine the OSX process which is presenting a dialog?

From Dev

How to determine if result of process substitution is a file path

From Dev

how to determine the max user process value?

From Dev

How to obtain handles for all children process of current process in Windows?

From Dev

How to handle variable number of process variables in Camunda

From Dev

How to handle long running process using TPL

From Dev

How to handle a rails endless / infinite process

From Dev

How to check is there a process running with the given handle

Related Related

  1. 1

    Determine whether the parent process is a terminal

  2. 2

    How to determine whether a process's privilege exists and its enabled/disabled?

  3. 3

    How to check whether a process is daemon or not?

  4. 4

    How can I determine if a process is a system process?

  5. 5

    How to get the process handle of an elevated process?

  6. 6

    How to determine whether a process is running or not and make use it to make a conditional shell script?

  7. 7

    How to determine if a process has GUI or not?

  8. 8

    Determine at runtime whether the "Visual Studio Hosting Process" is enabled?

  9. 9

    How to get file handle of a process?

  10. 10

    How to handle signal in foreground process?

  11. 11

    how to unshare network for current process

  12. 12

    How does the fork() know whether it is in child process and in parent process?

  13. 13

    Lua: how to check whether a process is running

  14. 14

    How to check whether the process was restarted by supervisor?

  15. 15

    How to know whether a process ended in JBPM

  16. 16

    How can I determine if process is user program or simply a process

  17. 17

    determine current process priority from within a running bash script

  18. 18

    How to determine if a process runs inside lxc/Docker?

  19. 19

    How to determine there are no running jobs or consumer process exit

  20. 20

    How to determine the process responsible for an intermittent packet?

  21. 21

    How to determine which process owns a toplevel window?

  22. 22

    How to determine the OSX process which is presenting a dialog?

  23. 23

    How to determine if result of process substitution is a file path

  24. 24

    how to determine the max user process value?

  25. 25

    How to obtain handles for all children process of current process in Windows?

  26. 26

    How to handle variable number of process variables in Camunda

  27. 27

    How to handle long running process using TPL

  28. 28

    How to handle a rails endless / infinite process

  29. 29

    How to check is there a process running with the given handle

HotTag

Archive