What processing / validation is done in command line arguments before the process starts?

I have a small WPF application that takes file paths as command line arguments.

If the user drags too many files with long paths, he will exceed the maximum command line length, at least on 32-bit WinXP.

As a result, a window appears with an error message:

Windows cannot access the specified device, path, or file. You cannot have the appropriate permissions to access the item.

It seems like a mistake

The file name or extension is too long.

In these cases, it seems that the process never starts.

I thought that drag-and-drop files effectively simply pass their paths as strings, but these errors indicate the opposite, and that some part of the OS / shell / shell does some kind of verification based on the fact that this is the path to files / directories, and when this fails, the process does not start.

Does anyone know what happens between the moment when command line arguments are passed to .NET.exe and when this .exe is launched, if ever?

+4
source share
1 answer

The answer to your question: the list of paths exceeds the maximum command line size, so your program cannot run.

The operating system creates a command line before the process starts, as this information is required during the creation of the process. Since the length of the command line exceeds the maximum size, the operating system cannot build it and does not work, possibly with ERROR_FILENAME_EXCED_RANGE ( sic ) before even trying to create a process.

Therefore, your program never starts.

+4
source

Source: https://habr.com/ru/post/1334705/


All Articles