简体   繁体   中英

What processing/validation is performed on command line arguments before a process starts?

I've a small WPF application that accepts file paths as command line arguments.

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

The result is an error window showing:

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

This appears similar to the error

The filename or extension is too long.

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

I thought that drag-and-dropping files effectively just passed their paths as strings, but these errors indicate otherwise, and that some part of the OS/shell/framework is doing some kind of validation based on the fact that these are file/directory paths, and when that fails, the process does not start.

Does anyone know what happens between the time that command line arguments are passed to a .NET .exe and when that .exe starts up, if ever?

The answer is in your question: the path list exceeds the maximum command line size, so your program cannot start.

The operating system builds the command line before it starts your process, since that information is required at process creation time. Since the command line length exceeds the maximum size, the operating system can't build it and fails, probably with ERROR_FILENAME_EXCED_RANGE ( sic ), before even trying to create the process.

Therefore, your program never starts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM