Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
PSAPI Reference
PSAPI Functions
 EnumProcesses Function

  Switch on low bandwidth view
EnumProcesses Function

Retrieves the process identifier for each process object in the system.

Syntax

C++
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 PSAPI version 2 for Windows 7 and Windows Server 2008 R2, this function is defined as K32EnumProcesses in Psapi.h and exported in Kernel32.lib and Kernel32.dll. However, you should always call this function as EnumProcesses. To ensure correct resolution of symbols for programs that will run on earlier versions of Windows, add Psapi.lib to the TARGETLIBS macro and compile the program with –DPSAPI_VERSION=1.

Examples

For an example, see Enumerating All Processes or Enumerating All Modules for a Process.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderPsapi.h
LibraryKernel32.lib on Windows 7 and Windows Server 2008 R2, Psapi.lib on Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000
DLLKernel32.dll on Windows 7 and Windows Server 2008 R2, Psapi.dll on Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000

See Also

CreateToolhelp32Snapshot
OpenProcess
Process Information
PSAPI Functions

Send comments about this topic to Microsoft

Build date: 7/2/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("psapi.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function EnumProcesses(ByVal processIds As Integer(), ByVal size As Integer, <Out> ByRef needed As Integer) As Boolean End Function
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("psapi.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool EnumProcesses(int[] processIds, int size, out int needed);
Tags What's this?: c# (x) syntax (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker