VC++ 2008, OpenProcess always returning error 5 (Access Denied)

眉间皱痕 提交于 2019-12-01 09:36:18

Opening a process with full access rights can be a highly privileged operation if it's not a process running under you credentials or in your logon session - you'll need to follow this bit of documentation from MSDN:

To open a handle to another process and obtain full access rights, you must enable the SeDebugPrivilege privilege. For more information, see Changing Privileges in a Token.

Remember that even if you have a privilege, in most cases the privilege is not enabled - it has to be specifically enabled in the code that's attempting to use the privilege.

Another thing that might be causing this is new to Vista:

Windows Vista introduces protected processes to enhance support for Digital Rights Management. The system restricts access to protected processes and the threads of protected processes.

The following standard access rights are not allowed from a process to a protected process:

DELETE READ_CONTROL WRITE_DAC WRITE_OWNER

Which process is it? Opening a service or a process in another user session is likely to return Access Denied (5). A process in another session will open for read but you wouldn't be able to debug it. It's one reason why Windbg has the non-intrusive attach. It works across user sessions. You're not actually debugging. It suspends all the threads and is reading the memory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!