GetConsoleTitle function


This document describes console platform functionality that is no longer a part of our ecosystem roadmap. We do not recommend using this content in new products, but we will continue to support existing usages for the indefinite future. Our preferred modern solution focuses on virtual terminal sequences for maximum compatibility in cross-platform scenarios. You can find more information about this design decision in our classic console vs. virtual terminal document.

Retrieves the title for the current console window.


DWORD WINAPI GetConsoleTitle(
  _Out_ LPTSTR lpConsoleTitle,
  _In_  DWORD  nSize


lpConsoleTitle [out]
A pointer to a buffer that receives a null-terminated string containing the title. If the buffer is too small to store the title, the function stores as many characters of the title as will fit in the buffer, ending with a null terminator.

nSize [in]
The size of the buffer pointed to by the lpConsoleTitle parameter, in characters.

Return value

If the function succeeds, the return value is the length of the console window's title, in characters.

If the function fails, the return value is zero and GetLastError returns the error code.


To set the title for a console window, use the SetConsoleTitle function. To retrieve the original title string, use the GetConsoleOriginalTitle function.

This function uses either Unicode characters or 8-bit characters from the console's current code page. The console's code page defaults initially to the system's OEM code page. To change the console's code page, use the SetConsoleCP or SetConsoleOutputCP functions. Legacy consumers may also use the chcp or mode con cp select= commands, but it is not recommended for new development.


This API is not recommended and does not have a virtual terminal equivalent. This decision intentionally aligns the Windows platform with other operating systems. Applications remoting via cross-platform utilities and transports like SSH may not work as expected if using this API.


For an example, see SetConsoleTitle.


Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Header ConsoleApi2.h (via WinCon.h, include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll
Unicode and ANSI names GetConsoleTitleW (Unicode) and GetConsoleTitleA (ANSI)

See also

Console Functions