获取原始(未分割)命令行中的.NET命令行、原始、NET

2023-09-03 15:51:53 作者:春风得意马蹄疾

在.NET中,我们可以很容易地从主(字符串[])环境参数访问分割命令行参数的字符串数组.GetCommandLineArgs()。但是,有没有办法让非解析命令行作为一个字符串?

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?

背景:我的应用程序添加自己FileExplorer上下文菜单(如记事本++一样)。时,它的发射这种方式,文件名被传递,而不引用,这意味着如果有在路径中的空间,它的细分。我知道我可以拥抱%1 用引号引起来解决此问题在注册表中如 MyApp.exe将%1 ,但是当我检查其他应用程序的注册表中,他们并没有这样做。他们是普通的像 NOTEPAD.EXE%1 - 他们得到了完整的命令行。我想知道是否有可能在.NET和如何。

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.

推荐答案

尝试使用Environment.CommandLine

Try using Environment.CommandLine

 
精彩推荐
图片推荐