使用关联的应用程序打开文件 [英] Open file with associated application

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

问题描述

我想寻求帮助,从带有关联应用程序的 c# 应用程序打开文件.我试过这个:

i want to ask for help with opening a file from c# app with associated app. I tried this:

      ProcessStartInfo pi = new ProcessStartInfo(file);
      pi.Arguments = Path.GetFileName(file);
      pi.UseShellExecute = true;
      pi.WorkingDirectory = Path.GetDirectoryName(file);
      pi.FileName = file;
      pi.Verb = "OPEN";
      Process.Start(pi);

或者这个:

      Process.Start(file);

其中两个示例中的字符串 file 表示尝试打开的文件的完整路径.现在,除了带有 ACDSee 应用程序的 (jpg) 图像之外,一切都运行良好.Irfanview 协会运作良好,MS Office 文档也运作良好.尝试打开与 acdsee 关联的 jpg 图像后,它只会在通知区域中运行 acdsee 而不会打开文件.

where string file in both examples represents full path to the file trying to open. Now, everything is working well, except the (jpg) images with ACDSee app. Irfanview associations works well, MS office documents too. After trying to open the jpg image associated with acdsee it just runs the acdsee in the notification area and does not open the file.

我发现,在注册表 CLASSES_ROOT 对于 *.jpg 图像,有一个 ACDSee.JPG 值作为关联的应用程序,在此键下有在 shell->;打开->命令路径:

I discovered, that in the registry CLASSES_ROOT for *.jpg images, there is an ACDSee.JPG value as associated app, and under this key there is in the shell->Open->Command a path:

"C:Program FilesACD SystemsACDSeeACDSee.exe" /dde

我认为这个奇怪的 /dde 是我无法打开文件的原因.我意识到在同一个注册表键 shell->Open 中有一些 DDEExec 键条目,其值为 [open("%1")]

and I thing that this weird /dde is the reason, why i cannot open the file. I realized that in the same reg key shell->Open there is some DDEExec key entry with value [open("%1")]

对于 Irfan 视图或其他已检查的应用程序,没有 ddeexec,只是像

For Irfan view or other checked app there is not a ddeexec, just the normal command like

"C:Program Files (x86)IrfanViewi_view32.exe" "%1"

可以在将 %1 交换为文件名后从命令行运行,但是我无法从命令行中的 acdsee 条目运行该命令:(

that can be run from command line after swaping the %1 for file name, but I could not run the command from acdsee entry in the command line :(

所以我的问题是,如何设置 ProcessStartInfo 对象以确保它将运行所有文件,就像它在资源管理器中双击一样,标准和这个 DDEExec 的?还有其他类似 DDEExec 的东西我应该注意吗?感谢和抱歉我的英文

So my question is, how can I set up the ProcessStartInfo object to ensure that it will run all the files as it would be in the explorer by doubleclick, the standards and this DDEExec ones? Is there something other like DDEExec that I shoul be aware of? thanks and sorry for my EN

更新:因为这个问题仍然得到赞成,我想澄清接受的答案是有效的.我只有旧版本的 ACDSee 有问题,而不是 Process.Start 命令或 jpg 扩展.

UPDATE: because this question still gets upvotes, I want to clarify that accepted answer works. I only had problem with old version of ACDSee and not with the Process.Start command or with the jpg extension.

推荐答案

直接写

System.Diagnostics.Process.Start(@"file path");

例子

System.Diagnostics.Process.Start(@"C:foo.jpg");
System.Diagnostics.Process.Start(@"C:foo.doc");
System.Diagnostics.Process.Start(@"C:foo.dxf");
...

Shell 将运行相关程序从注册表中读取它,就像通常的双击一样.

And shell will run associated program reading it from the registry, like usual double click does.

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

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