OpenProcess使用PROCESS_ALL_ACCESS返回ERROR_ACCESS_DENIED

原文地址

http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/eeb93be6-872c-4028-b0ae-cd873e089825

 

Rajeesh... _

Rajeesh... _

Ness technologies

280 Points 5 0 0
Recent Achievements
First Helpful Vote Forums Replies I Forums Answerer I
Ness technologies

280 Points

  
I just went through OpenProcess API in msdn, it says below for for PROCESS_ALL_ACCESS. I think this was the issue which you were facing.

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, seeUsing the Windows Headers .

  • Proposed As Answer by Yi Feng LiMicrosoft Contingent Staff, ModeratorWednesday, July 14, 2010 8:37 AM
  • Marked As Answer by Yi Feng LiMicrosoft Contingent Staff, ModeratorTuesday, July 20, 2010 1:40 AM

 

Windows Server 2008及Windows Vista上PROCESS_ALL_ACCESS的标志有所增加,如果应用程序编译时的target OS是Windows Server 2008或Windows Vista, 但却运行在Windows Server 2003或Windows XP/2000上,PROCESS_ALL_ACCESS太大,指定这个标志的函数会返回ERROR_ACCESS_DENIED错误。如果避免这个错误,指定操作所需的最小访问权限,而不是图省事指定PROCESS_ALL_ACCESS. 如果必须要用PROCESS_ALL_ACCESS, 要在程序中定义_WIN32_WINNT _WIN32_WINNT_WINXP

你可能感兴趣的:(编程)