Getting raw (unsplit) command line in .NET

.net, c#, command-line-arguments

Solution

Try using: `Environment.CommandLine`

Problem

In .NET, we can easily access split command line arguments in a string array from the argument of `Main(string[])` or `Environment.GetCommandLineArgs()`. However, is there a way to get the unparsed command line as one string? Background: my app is adding itself to FileExplorer context menu (like Notepad++ does). When it's launched this way, the filename is passed in without quoting, which means if there are spaces in the path, it's broken down. I know I can fix this by embrace `%1` in quotation marks in the registry like `myapp.exe "%1"`, but when I check other application's registry they didn't do so. They are plain like `notepad.exe %1` - they got the complete command line. I want to know if it is possible in .NET and how.

Original source

Related problems