关于winapi:C WriteProcessMemory错误INVALID_HANDLE_VALUE

C++ WriteProcessMemory error INVALID_HANDLE_VALUE

我正在使用" CreateRemoteThread


问题出在您的OpenProcess呼叫中。从此处:http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms684880(v=vs.85).aspx,列在PROCESS_ALL_ACCESS访问权限下:

Windows Server 2003 and Windows XP: The size of the PROCESS_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP, the PROCESS_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example, #define _WIN32_WINNT _WIN32_WINNT_WINXP). For more information, see Using the Windows Headers.

因此,可能未设置PROCESS_VM_READPROCESS_VM_OPERATION,因此稍后出现无效句柄错误。我知道OpenProcess确实应该在失败时返回错误代码-并非如此-但是如果此标志确实溢出,我可以看到无声失败可能发生。