c++processopenprocess

Vista/7 compile and XP/2000 execution issues with OpenProcess in C++


I've been using OpenProcess with PROCESS_ALL_ACCESS rights for the following functions: -EnumProcessModules
-GetModuleFileNameEx
-ReadProcessMemory
-WriteProcessMemory
which works fine on Windows Vista/7. However, in Windows XP/2000, it won't open the process with PROCESS_ALL_ACCESS because according to the MSDN library:


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)

I'm not familiar with using #define to set the minimum operating system. After trying several combinations of alternative access rights for the functions listed above, all without luck, I ask if someone may show me how to define the minimum operating system using #define (the above example didn't work) and/or which process rights would be needed for those functions.

Many thanks.


Solution

  • Find the location of your #include <windows.h> directive and make it look like this:

    #define _WIN32_WINNT 0x500   // Target Windows 2000
    #include <windows.h>