1 2 unit Unit1; 3 4 interface 5 6 uses 7 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 8 Dialogs,shellapi, StdCtrls; 9 10 type 11 TForm1 = class(TForm) 12 Button1: TButton; 13 procedure Button1Click(Sender: TObject); 14 private 15 { Private declarations } 16 public 17 { Public declarations } 18 end; 19 20 var 21 Form1: TForm1; 22 23 implementation 24 25 {$R *.dfm} 26 27 procedure TForm1.Button1Click(Sender: TObject); 28 29 var 30 sApp : array [0..256] of char; 31 begin 32 //this code should return notepad.exe 33 //*.xls would be excel.exe 34 //*.doc would be winword.exe 35 36 if FindExecutable('c:\test.txt', nil, sApp) >= 32 then 37 ShowMessage(sApp) 38 else 39 ShowMessage(SysErrorMessage(GetLastError)); 40 41 end; 42 43 end.