Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm having issues trying to get the the default application for text files on a users machine.

I've tried
C#
Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("txtfile").GetValue("FriendlyTypeName")


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
Posted

1 solution

Well, you could use FindExecutable[^]
C#
[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());
 
Share this answer
 
Comments
sHoE_FeRReT 27-Feb-14 6:53am    
Thanks alot that works Great!
OriginalGriff 27-Feb-14 7:05am    
You're welcome!
Maciej Los 27-Feb-14 6:56am    
+5
Luc Pattyn 24-Nov-17 20:52pm    
Hi OG, your solution is fine for a specific and existing file ("a text file" in the title), not for files with ".txt" extension ("text files" in the question's body). Then PInvoking AssocQueryString() would probably be the right way to go.

:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900