C#打开文件相关联的应用程序传递参数 [英] C# Open File With Associated Application passing arguments

查看:275
本文介绍了C#打开文件相关联的应用程序传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我试图推出延期指定一个额外的参数注册的默认应用程序:


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:

<一个href=\"http://stackoverflow.com/questions/162331/finding-the-default-application-for-opening-a-particular-file-type-on-windows\">Finding在Windows

这篇关于C#打开文件相关联的应用程序传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆