GetCommandLineW function (processenv.h)

Retrieves the command-line string for the current process.

Syntax

LPWSTR GetCommandLineW();

Return value

The return value is a pointer to the command-line string for the current process.

Remarks

The lifetime of the returned value is managed by the system, applications should not free or modify this value.

Console processes can use the argc and argv arguments of the main or wmain functions by implementing those as the program entry point. GUI processes can use the lpCmdLine argument of the WinMain or wWinMain functions by implementing those as the program entry point.

To convert the command line to an argv style array of strings, pass the result from GetCommandLineW to CommandLineToArgvW.

Note  The name of the executable in the command line that the operating system provides to a process is not necessarily identical to that in the command line that the calling process gives to the CreateProcess function. The operating system may prepend a fully qualified path to an executable name that is provided without a fully qualified path.
 

Note

The processenv.h header defines GetCommandLine as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps | UWP apps]
Minimum supported server Windows Server 2003 [desktop apps | UWP apps]
Target Platform Windows
Header processenv.h (include Windows.h on Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008 Windows Server 2008 R2)
Library Kernel32.lib
DLL Kernel32.dll

See also

CreateProcess

Process and Thread Functions