开发者

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 o开发者_高级运维n 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜