寻找在Windows打开一个特定的文件类型的默认应用程序
我正在开发面向.NET Framework 2.0中使用C#的,我需要能够找到一个用于打开特定文件类型的默认应用程序的应用程序。
I'm developing an application targeting .NET Framework 2.0 using C# for which I need to be able to find the default application that is used for opening a particular file type.
我知道,例如,如果你只是想使用的应用程序,你可以使用像打开文件:
I know that, for example, if you just want to open a file using that application you can use something like:
System.Diagnostics.Process.Start( "C:\...\...\myfile.html" );
要在默认浏览器中打开HTML文档,或
to open an HTML document in the default browser, or
System.Diagnostics.Process.Start( "C:\...\...\myfile.txt" );
要打开默认的文本编辑器的文本文件。
to open a text file in the default text editor.
不过,我希望能够做的就是打开不一定具有的 .TXT 的扩展名(例如),在默认的文本编辑器,所以我需要的文件能够找出打开默认应用程序的 .TXT 的文件,这将使我直接调用它。
However, what I want to be able to do is to open files that don't necessarily have a .txt extension (for example), in the default text editor, so I need to be able to find out the default application for opening .txt files, which will allow me to invoke it directly.
我猜有一些Win32 API的,我需要的P / Invoke,为了做到这一点,但是咋一看与谷歌和MSDN并没有透露太多的兴趣的事情;我没有找到一个非常大的数字的完全不相干的页面,但没有像我期待的。如果有人知道它的API /方法,我应该用我会很高兴收到你的来信。
I'm guessing there's some Win32 API that I'll need to P/Invoke in order to do this, however a quick look with both Google and MSDN didn't reveal anything of much interest; I did find a very large number of completely irrelevant pages, but nothing like I'm looking for. If anyone knows which API/methods I should be using I'd be very happy to hear from you.
非常感谢!
您可以检查在注册表部分 HKEY_CLASSES_ROOT
的延伸和行动的细节。文档这是MSDN 。另外,您也可以使用 IQueryAssociations 接口。
You can check under registry section HKEY_CLASSES_ROOT
for the extension and action details. Documentation for this is on MSDN. Alternatively, you can use the IQueryAssociations interface.