// efg, 3 Aug 2000 // www.efg2.com/Lab unit OpenWithExample; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} USES ShellAPI; // Filename is fully-qualified file name // (based on 3 Aug 2000 E-mail from Gunnar Einarsson) PROCEDURE OpenWith(FileName: STRING); BEGIN ShellExecute(Form1.handle, pChar('open'), pChar('rundll32.exe'), pChar('shell32.dll,OpenAs_RunDLL ' + pChar(FileName)), nil, SW_SHOW); END; procedure TForm1.Button1Click(Sender: TObject); begin OpenWith('C:\Program Files\Windows NT\Accessories\wordpad.exe') end; end.