C#4.0:有没有办法检查System.Diagnostics.Process.Start中是否不存在应用程序

时间:2010-04-27 00:45:37

标签: c#-4.0 system.diagnostics

我想使用以下代码打开任何文件类型:

System.Diagnostics.Process.Start(pathFile);

有没有办法检查系统应用程序是否不存在?

例如:pdf,本地机器没有acrobat reader。

我创建了一个try catch,但是我对它不满意,我想在打开文件时模仿windows的行为。它有一个搜索Web /手动搜索选项。

try
            {
                System.Diagnostics.Process.Start(pathFile);
            }
            catch (System.ComponentModel.Win32Exception ex)
            {

                composite.ReadingError = ex.Message;
                Console.WriteLine("error");
            }

2 个答案:

答案 0 :(得分:2)

您需要使用PInvoke(FindExecutable(shell32)):

答案 1 :(得分:0)

如果没有关联,它应该抛出你可以捕获的Win32Exception

请参阅此处:例外部分中的http://msdn.microsoft.com/en-us/library/53ezey2s.aspx