什么样的处理/验证命令行参数执行的过程开始前?命令行、参数、过程

2023-09-04 12:01:56 作者:天长地久

我已经接受文件路径作为命令行参数的小WPF应用程序。

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

如果用户拖动在太多的文件具有长的路径,这将超过最大命令行的长度,至少在32位的WinXP

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无法访问指定的   装置,路径或文件。你不可以   有适当的权限   访问该项目。

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

这似乎类似的错误

文件名或扩展名是太长。

The filename or extension is too long.

在这种情况下,似乎该过程从未启动

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

我有效地以为拖和文件拖放刚刚通过的路径字符串,但这些错误指示,否则,那OS /壳/框架的某些部分做一些验证基于这样的事实,这些都是文件/目录路径,并且当发生故障时,该过程不启动

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.

有谁知道命令行参数传递给.NET .exe和时.EXE启动,如果有的话?

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.

操作系统构建命令行开始之前的过程,因为这需要信息的过程中创建时间。由于命令行的长度超过了最大大小,操作系统不能建立它和失败,可能与 ERROR_FILENAME_EXCED_RANGE (原文)之前,甚至试图创建过程。

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.