HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
//XP下打开句柄失败! WIN7下打开句柄成功!
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
什么原因导致XP下失败?
4 个解决方案
#1
你的程序编译时用了比较新的头文件,那里面的PROCESS_ALL_ACCESS包含了比xp下的PROCESS_ALL_ACCESS更多的存取掩码,因此有一些在xp下无效
比如xp下没有PROCESS_QUERY_LIMITED_INFORMATION,但你的头文件就包含了这个
msdn:
All possible access rights for a process object.
Windows Server 2003 and Windows XP/2000: 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/2000, 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.
比如xp下没有PROCESS_QUERY_LIMITED_INFORMATION,但你的头文件就包含了这个
msdn:
All possible access rights for a process object.
Windows Server 2003 and Windows XP/2000: 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/2000, 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.
#2
照这个意思,用旧版本比较好,不要追新喽?
#3
你需要干什么就用什么,比如要写内存和结束进程就用PROCESS_VM_WRITE|PROCESS_TERMINATE
如果一定要用PROCESS_ALL_ACCESS,就用2035711,这个是都可用的
如果一定要用PROCESS_ALL_ACCESS,就用2035711,这个是都可用的
#4
学习了,谢谢!
#1
你的程序编译时用了比较新的头文件,那里面的PROCESS_ALL_ACCESS包含了比xp下的PROCESS_ALL_ACCESS更多的存取掩码,因此有一些在xp下无效
比如xp下没有PROCESS_QUERY_LIMITED_INFORMATION,但你的头文件就包含了这个
msdn:
All possible access rights for a process object.
Windows Server 2003 and Windows XP/2000: 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/2000, 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.
比如xp下没有PROCESS_QUERY_LIMITED_INFORMATION,但你的头文件就包含了这个
msdn:
All possible access rights for a process object.
Windows Server 2003 and Windows XP/2000: 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/2000, 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.
#2
照这个意思,用旧版本比较好,不要追新喽?
#3
你需要干什么就用什么,比如要写内存和结束进程就用PROCESS_VM_WRITE|PROCESS_TERMINATE
如果一定要用PROCESS_ALL_ACCESS,就用2035711,这个是都可用的
如果一定要用PROCESS_ALL_ACCESS,就用2035711,这个是都可用的
#4
学习了,谢谢!