如何获取txt文件的关联程序? [英] How do I get the associated program for a txt file?
问题描述
您好,
我在尝试获取用户计算机上文本文件的默认应用程序时遇到问题。
我试过了
Hello,
I'm having issues trying to get the the default application for text files on a users machine.
I've tried
Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("txtfile").GetValue("FriendlyTypeName")
但它总是返回标准窗口notepad.exe
这是错误的,因为在我的机器上.txt文件与Brackets.exe相关联,如果我双击txt文件就会加载。
I我需要知道应用程序,因为我有很多与其他程序相关的自定义文件扩展名,但文件是纯文本,因此可以在文本编辑器中查看。
我应该在注册表中的其他地方吗?
谢谢
But it always returns the standard windows notepad.exe
This is wrong because on my machine .txt files are associated with Brackets.exe and this is what loads if I double click on a txt file.
I need to know the application because I have a lot of custom file extensions that are associated to other programs, but the files are plain text so can be viewed in a text editor.
Is there somewhere else in the registry I should be looking?
Thanks
推荐答案
好吧,你可以使用 FindExecutable [ ^ ]
Well, you could use FindExecutable[^]
[DllImport("shell32.dll")]
static extern int FindExecutable(string lpFile, string lpDirectory, [Out] StringBuilder lpResult);
...
StringBuilder sb = new StringBuilder(1024);
int i = FindExecutable(@"D:\Temp\AAAA.txt", null, sb);
Console.WriteLine(sb.ToString());
这篇关于如何获取txt文件的关联程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!