none
OpenProcess error in Windows XP?

    Question

  • Hi,

    HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
    
    I'm debugging my program and the above code works in all of my systems except my Windows XP SP3. I'm coding this  in Visual C++ 2010, on Windows 7 32bit. On my XP SP3 systems, it returns an error while trying to execute the above code. What could be the problem? 

    Monday, July 12, 2010 5:35 PM

Answers

  • 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, see Using the Windows Headers .

    Tuesday, July 13, 2010 5:03 AM

All replies

  • If OpenProcess fails and returns null, then call GetLastError() to get a code that could explain the error.

    Monday, July 12, 2010 6:11 PM
  • Hmm, XP systems seem to dislike PROCESS_ALL_ACCESS. I used PROCESS_VM_READ and now it works fine.
    Monday, July 12, 2010 8:56 PM
  • 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, see Using the Windows Headers .

    Tuesday, July 13, 2010 5:03 AM