Platform SDK: Performance Monitoring

EnumProcesses

The EnumProcesses function retrieves the process identifier for each process object in the system.

BOOL EnumProcesses(
  DWORD *lpidProcess,  // array of process identifiers
  DWORD cb,            // size of array
  DWORD *cbNeeded      // number of bytes returned
);

Parameters

lpidProcess
[out] Pointer to an array that receives the list of process identifiers.
cb
[in] Specifies the size, in bytes, of the lpidProcess array.
cbNeeded
[out] Receives the number of bytes returned in the lpidProcess 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 give EnumProcesses a large array of DWORD values, 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 by the call to EnumProcesses, divide the resulting value in the cbNeeded parameter by sizeof(DWORD). There is no indication given when the buffer is too small to store all process identifiers.

To obtain process handles for the processes whose identifiers you have just obtained, call the OpenProcess function.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Header: Declared in Psapi.h.
  Library: Use Psapi.lib.

See Also

Process Status Helper Overview, PSAPI Functions, OpenProcess