Solved

Application associated with file type

Posted on 2004-08-06
8
185 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

820 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