Solved

Application associated with file type

Posted on 2004-08-06
8
187 Views
Last Modified: 2010-04-05
How do I find application name associated with a file extension,
for example; MDB -> Microsoft Access, TXT -> Notepad etc
0
Comment
Question by:graga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 4

Expert Comment

by:ErikPhilips
ID: 11739697
Solution 1:
- Open Explorer (to anywhere, my documents, c:\ whatever, where explorer opens to is irrelevant)
- from the menu Tools -> Options -> File Types.

Solution 2:
- Open Regedit
- File the Registry Path My Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
0
 

Author Comment

by:graga
ID: 11739907
Solution 1 is no good, It needs to be done from my Delphi application

Solution 2 gives me program executable, not application name. In my example, mdb gives msaccess.exe instead of Microsoft Access.
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11740132
This should do it...

var
  e,s:string;
  R:tRegistry;
begin
  E:='psd';
  R:=TRegistry.Create;
  try
    R.RootKey := HKEY_CLASSES_ROOT;
    if R.OpenKey('.'+E,False) then begin
      S:=R.ReadString('');
      R.CloseKey;
      if (S<>'') and R.OpenKey(S,False) then begin
        S:=R.ReadString('');  //S has the "name"
        Message(E+' = '+S);
        R.CloseKey;
      end;
    end;
  finally
    R.Free;
  end;
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:LRHGuy
ID: 11740137
Oh, change  E:='psd' to whatever extension you're looking for..lowercase.

Enjoy!
0
 

Author Comment

by:graga
ID: 11740652
Thanks LRHGuy,

This is very close. However, the code returns file type instead of application name, for example,
'DOC' returns 'Microsoft Word Document' instead of 'Microsoft Word'
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11741102
Here are the changes...it's a long trek...I leave the error checking to you...

E:='psd';

    R.RootKey:=HKEY_CURRENT_USER;
    if R.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.'+E+'\OpenWithList',false) then begin
      S:=R.ReadString('MRUList');
      S:=R.ReadString(S);
      R.CloseKey;
    end;
    R.RootKey:=HKEY_CLASSES_ROOT;
    if R.OpenKey('Applications\'+S+'\shell',false) then begin
      S:=R.ReadString('FriendlyCache');
      R.CloseKey;
      Message(E+' = '+S);
    end;

0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11741108
I suppose that doesn't find something in all cases. It found psd, ppp, and some others, but it doesn't seem to find doc or txt. ARGH!
0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 125 total points
ID: 11741114
This seems to fix it...


E:='psd';

    R.RootKey:=HKEY_CURRENT_USER;
    if R.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.'+E+'\OpenWithList',false) then begin
      S:=R.ReadString('MRUList');
      S:=R.ReadString(copy(S,1,1));  //looks at first item in list
      R.CloseKey;
    end;
    R.RootKey:=HKEY_CLASSES_ROOT;
    if R.OpenKey('Applications\'+S+'\shell',false) then begin
      S:=R.ReadString('FriendlyCache');
      R.CloseKey;
      Message(E+' = '+S);
    end;

 
 
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month3 days, 20 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question