GetConsoleProcessList function

Retrieves a list of the processes attached to the current console.

Syntax

DWORD WINAPI GetConsoleProcessList(
  _Out_ LPDWORD lpdwProcessList,
  _In_  DWORD   dwProcessCount
);

Parameters

lpdwProcessList [out]
A pointer to a buffer that receives an array of process identifiers upon success. This must be a valid buffer and cannot be NULL. The buffer must have space to receive at least 1 returned process id.

dwProcessCount [in]
The maximum number of process identifiers that can be stored in the lpdwProcessList buffer. This must be greater than 0.

Return value

If the function succeeds, the return value is less than or equal to dwProcessCount and represents the number of process identifiers stored in the lpdwProcessList buffer.

If the buffer is too small to hold all the valid process identifiers, the return value is the required number of array elements. The function will have stored no identifiers in the buffer. In this situation, use the return value to allocate a buffer that is large enough to store the entire list and call the function again.

If the return value is zero, the function has failed, because every console has at least one process associated with it. To get extended error information, call GetLastError.

If a NULL process list was provided or the process count was 0, the call will return 0 and GetLastError will return ERROR_INVALID_PARAMETER. Please provide a buffer of at least one element to call this function. Allocate a larger buffer and call again if the return code is larger than the length of the provided buffer.

Remarks

To compile an application that uses this function, define _WIN32_WINNT as 0x0501 or later. For more information, see Using the Windows Headers.

Tip

This API is not recommended and does not have a virtual terminal equivalent. This decision intentionally aligns the Windows platform with other operating systems. This state is only relevant to the local user, session, and privilege context. Applications remoting via cross-platform utilities and transports like SSH may not work as expected if using this API.

Requirements

   
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Header ConsoleApi3.h (via WinCon.h, include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See also

AttachConsole

Console Functions