Delphi Program to obtain the application associated with the corresponding extension file name. The Code is as follows: Unit unit1; interface uses Windows, messages, registry, inifiles, sysutils, variants, classes, graphics, controls, form S, dialogs, stdctrls; Type tform 1 = Class (tform) button1: tbutton; Procedure button1click (Sender: tobject); Private {private Declarations} public {public declarations} end; vaR Form 1: tform 1; implementation {$ R *. DFM} function getprogramassociation (ext: string): string; // obtain the associated file var REG: Tregistry; s: string; winini: Tinifile; wininifilename: array [0 .. max_path] of char; begin S: = ''; Reg: = Tregistry. create; // generate registry object Reg. rootkey: = hkey_classes_root; If Reg. openkey ('. '+ ext +' \ shell \ open \ command ', false) <> false then // open the specified key value begin S: = reg. readstring (''); Reg. closekey; end else begin // if you cannot open If Reg. openkey ('. '+ Ext, false) <> false then begin S: = reg. readstring (''); Reg. closekey; if S <> ''then begin If Reg. openkey (S + '\ shell \ open \ command', false) <> false then s: = reg. readstring (''); Reg. closekey; end; If pos ('%', s)> 0 Then delete (S, pos ('%', S), length (s )); if (length (s)> 0) and (S [1] = '"') Then delete (s, 1, 1); If (length (s)> 0) and (S [length (s)] = '"') Then delete (S, length (s), 1); While (length (s)> 0) and (S [length (s)] = #32) or (s [length (s)] = '"') do Delete (S, length (s ), 1); getwindowsdirectory (wininifilename, sizeof (wininifilename); // obtain the system directory strcat (wininifilename, '\ win. INI '); winini: = Tinifile. create (wininifilename); s: = winini. readstring ('extension', ext, ''); winini. free; {delete any command line} If pos ('^', s)> 0 Then delete (S, pos ('^', S), length (s )); result: = s; end; Procedure tform 1. button1click (Sender: tobject); begin showmessage (getprogramassociation ('gif'); end.
Obtain the application associated with the corresponding extension file name