C# 打开带有关联应用程序传递参数的文件 [英] C# Open File With Associated Application passing arguments
问题描述
我正在尝试启动为指定附加参数的扩展注册的默认应用程序:
I am trying to launch the default application registered for an extension specifying an additional argument:
ProcessStartInfo p = new ProcessStartInfo();
p.Arguments = "myargument";
p.FileName = "file.ext";
Process.Start(p);
应用程序开始正确打开指定的文件.问题是它只获取一个参数(文件名),完全忽略了额外的参数".
可以做我想做的事吗?难道我做错了什么?
The application starts correctly opening the specified file.
The problem is that it is getting just one parameter (the name of the file), totally ignoring the additional "Arguments".
Is it possible to do what I want?
Am I doing something wrong?
在此先感谢您的帮助,
保罗
Thanks in advance for any help,
Paolo
推荐答案
我相信这是意料之中的.在幕后,Windows 正在注册表中查找默认应用程序并创建一个新进程并将您的文件名传递给它.如果我转到命令提示符并键入 "filename.ext 参数",我会得到相同的行为,我的参数不会传递给应用程序.
I believe this is expected. Behind the scenes, Windows is finding the default application in the registry and creating a new process and passing your file name to it. I get the same behavior if I go to a command prompt and type "filename.ext argument", that my arguments are not passed to the application.
您可能需要做的是自己通过在注册表中查找默认应用程序.然后您可以使用参数开始该过程,而不是尝试通过文件类型关联开始.这里有一个关于如何在注册表中找到默认应用程序的答案:
What you probably need to do is find the default application yourself by looking in the registry. Then you can start that process with arguments, instead of trying to start by filetype association. There is an answer here on how to find the default application in the registry:
这篇关于C# 打开带有关联应用程序传递参数的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!