GetCommandLine Function
GetCommandLine Function

Retrieves the command-line string for the current process.

Syntax

LPTSTR WINAPI GetCommandLine(void);


Parameters

This function has no parameters.

Return Value

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

Remarks

ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The main and WinMain functions cannot return Unicode strings.

Unicode console process written in C can use the wmain or _tmain function to access the command-line arguments. Unicode GUI applications must use the GetCommandLineW function to access Unicode strings.

To convert the command line to an argv style array of strings, call the CommandLineToArgvW function.

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.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesGetCommandLineW (Unicode) and GetCommandLineA (ANSI)

See Also

CreateProcess
Process and Thread Functions

Send comments about this topic to Microsoft

Build date: 11/19/2009

Community Content

Another way to get the Unicode command line
Added by:Yuhong Bao
Another way to get the Unicode command line is to use the wWinMain or wmain function instead of WinMain or main. For ANSI/Unicode portablity use _tWinMain or _tmain.
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View