Need to refer to SHELLAPI unit;
Procedure Tform1.button1click (Sender:tobject); var seinfo:tshellexecuteinfo; Exitcode:dword; Executefile, paramstring, startinstring:string; Begin Executefile: = ' c:\Windows\system32\Calc.exe '; Fillchar (Seinfo, SizeOf (seinfo), #0); Seinfo.cbsize: = SizeOf (Tshellexecuteinfo); With Seinfo do begin fmask: = see_mask_nocloseprocess; Wnd: = Application.handle; Lpfile: = PChar (Executefile); Paramstring can contain the application parameters//Lpparameters: = PChar (paramstring); startinstring Specifies the name of the working Directory.if ommited, the current directory is used. Lpdirectory: = PChar (startinstring); Nshow: = Sw_shownormal; End If ShellExecuteEx (@SEInfo) then BEGIN repeat application.processmessages; GetExitCodeProcess (seinfo.hprocess, ExitCode); If ExitCode = Still_active then Sleep (500); Until (ExitCode <> still_active) or application.terminated; ShowmesSage (' Calculator terminated '); End Else ShowMessage (' Error starting calc! '); End
Delphi executes an external program, and when the external program finishes, the Delphi program responds immediately