EnumProcesses function
Retrieves the process identifier for each process object in the system.
Syntax
BOOL WINAPI EnumProcesses( __out DWORD *pProcessIds, __in DWORD cb, __out DWORD *pBytesReturned );
Parameters
- pProcessIds [out]
-
A pointer to an array that receives the list of process identifiers.
- cb [in]
-
The size of the pProcessIds array, in bytes.
- pBytesReturned [out]
-
The number of bytes returned in the pProcessIds array.
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
It is a good idea to use a large array, because it is hard to predict how many processes there will be at the time you call EnumProcesses.
To determine how many processes were enumerated, divide the pBytesReturned value by sizeof(DWORD). There is no indication given when the buffer is too small to store all process identifiers. Therefore, if pBytesReturned equals cb, consider retrying the call with a larger array.
To obtain process handles for the processes whose identifiers you have just obtained, call the OpenProcess function.
Starting with Windows 7 and Windows Server 2008 R2, Psapi.h establishes version numbers for the PSAPI functions. The PSAPI version number affects the name used to call the function and the library that a program must load.
If PSAPI_VERSION is 2 or greater, this function is defined as K32EnumProcesses in Psapi.h and exported in Kernel32.lib and Kernel32.dll. If PSAPI_VERSION is 1, this function is defined as EnumProcesses in Psapi.h and exported in Psapi.lib and Psapi.dll as a wrapper that calls K32EnumProcesses.
Programs that must run on earlier versions of Windows as well as Windows 7 and later versions should always call this function as EnumProcesses. To ensure correct resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program with –DPSAPI_VERSION=1. To use run-time dynamic linking, load Psapi.dll.
Examples
For an example, see Enumerating All Processes or Enumerating All Modules for a Process.
Requirements
Minimum supported client | Windows XP |
---|---|
Minimum supported server | Windows Server 2003 |
Header |
|
Library |
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 12/3/2011