Zav*_*ael 58 c# process file-association
我想请求帮助从c#app打开一个带有相关应用程序的文件.我试过这个:
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);
Run Code Online (Sandbox Code Playgroud)
或这个:
Process.Start(file);
Run Code Online (Sandbox Code Playgroud)
其中file两个示例中的字符串表示尝试打开的文件的完整路径.现在,除了使用ACDSee应用程序的(jpg)图像外,一切运行良好.Irfanview协会运作良好,MS办公室文件也是如此.试图打开使用ACDSee相关联的JPG图片后,它只是运行在通知区域中的ACDSEE,不打开该文件.
我发现,在注册表CLASSES_ROOT中为*.jpg图像,有一个ACDSee.JPG值作为关联应用程序,并且在此键下有一个shell- > Open-> Command命令路径:
"C:\Program Files\ACD Systems\ACDSee\ACDSee.exe" /dde
Run Code Online (Sandbox Code Playgroud)
我觉得这个奇怪/dde的原因,为什么我无法打开文件.我意识到在同一个reg key shell-> Open中有一些DDEExec带有值的键入口[open("%1")]
对于Irfan视图或其他已检查的应用程序,没有ddeexec,只有正常的命令
"C:\Program Files (x86)\IrfanView\i_view32.exe" "%1"
Run Code Online (Sandbox Code Playgroud)
可以在交换%1替换文件名后从命令行运行,但我无法从命令行中的acdsee条目运行命令:(
所以我的问题是,我如何设置ProcessStartInfo对象以确保它将运行所有文件,就像它在资源管理器中通过doubleclick,标准和这些DDEExec?还有其他类似的东西DDEExec我应该知道吗?谢谢,对不起我的EN
Tig*_*ran 111
写吧
System.Diagnostics.Process.Start(@"file path");
Run Code Online (Sandbox Code Playgroud)
例
System.Diagnostics.Process.Start(@"C:\foo.jpg");
System.Diagnostics.Process.Start(@"C:\foo.doc");
System.Diagnostics.Process.Start(@"C:\foo.dxf");
...
Run Code Online (Sandbox Code Playgroud)
shell将运行从注册表中读取它的相关程序,就像通常的双击一样.
小智 15
这是一个老线程,但万一有人遇到它像我一样.需要将pi.FileName设置为要用于打开文件的可执行文件的文件名(以及可能的文件的完整路径).以下代码适用于我用VLC打开视频文件.
var path = files[currentIndex].fileName;
var pi = new ProcessStartInfo(path)
{
Arguments = Path.GetFileName(path),
UseShellExecute = true,
WorkingDirectory = Path.GetDirectoryName(path),
FileName = "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe",
Verb = "OPEN"
};
Process.Start(pi)
Run Code Online (Sandbox Code Playgroud)
Tigran的答案有效但会使用Windows的默认应用程序打开您的文件,因此如果您想使用非默认应用程序打开文件,使用ProcessStartInfo可能会很有用.
在.Net Core(从v2.2开始)中,应为:
new Process
{
StartInfo = new ProcessStartInfo(@"file path")
{
UseShellExecute = true
}
}.Start();
Run Code Online (Sandbox Code Playgroud)
相关的github问题可以在这里找到
| 归档时间: |
|
| 查看次数: |
83933 次 |
| 最近记录: |