Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get a list of registered files and their extensions Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
29-Sep-02
Category
Files Operation
Language
Delphi 2.x
Views
68
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

Is there a Windows API that returns the name of the program that a particular file 
extension is associated with?

Answer:

Solve 1:

To get a list of the applications and their extensions for opening up files in 
Windows95 do the following:
1   
2   procedure TForm1.FormShow(Sender: TObject);
3   var
4     K: TRegIniFile;
5     i: Integer;
6     Extensions: TStringList;
7   begin
8     K := TRegIniFile.Create('');
9     K.RootKey := HKEY_LOCAL_MACHINE;
10    K.OpenKey('SOFTWARE\MicroSoft\Windows\CurrentVersion\Extensions', False);
11    Extensions := TStringList.Create;
12    K.GetValueNames(Extensions);
13    for i := 0 to Extensions.Count - 1 do
14      Memo1.Lines.Add(Extensions.Strings[i] + ' = ' + K.ReadString('',
15        Extensions.Strings[i], ''));
16    Extensions.Free;
17    K.Free;
18  end;



Solve 2:

Enumerate all extensions and their servers in the registry:
19  
20  procedure TForm1.Button1Click(Sender: TObject);
21  var
22    reg: TRegistry;
23    keys: TStringList;
24    i: Integer;
25    typename, displayname, server: string;
26  begin
27    memo1.clear;
28    reg := TRegistry.Create;
29    try
30      reg.rootkey := HKEY_CLASSES_ROOT;
31      if reg.OpenKey('', false) then
32      begin
33        keys := TStringlist.create;
34        try
35          reg.GetKeyNames(keys);
36          reg.closekey;
37          {memo1.lines.addstrings(keys);}
38          for i := 0 to keys.count - 1 do
39          begin
40            if keys[i][1] = '.' then
41            begin
42              {this is an extension, get its typename}
43              if reg.OpenKey(keys[i], false) then
44              begin
45                typename := reg.ReadString('');
46                reg.closekey;
47                if typename <> '' then
48                begin
49                  if reg.OpenKey(typename, false) then
50                  begin
51                    displayname := reg.readstring('');
52                    reg.closekey;
53                  end;
54                  if reg.OpenKey(typename + '\shell\open\command', false) then
55                  begin
56                    server := reg.readstring('');
57                    memo1.lines.add(format('Extension: "%s", Typename: "%s",
58  								 Displayname:"%s"'keys[i],
59  								 typename, displayname, server]));
60                    reg.closekey;
61                  end;
62                end;
63              end;
64            end;
65          end;
66        finally
67          keys.free;
68        end;
69      end;
70    finally
71      reg.free
72    end;
73  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC