//用CreateProcess
var
lpProcessInformation: TProcessInformation;
procedure TForm1.Button1Click(Sender: TObject);
var
StartupInfo : TStartupInfo;
begin
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
StartupInfo.cb := SizeOf(TStartupInfo);
StartupInfo.wShowWindow := SW_SHOW;
CreateProcess('d:/winnt/NOTEPAD.EXE', nil, nil, nil, False, 0, nil, nil, StartupInfo, lpProcessInformation);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
lpExitCode: DWORD;
begin
GetExitCodeProcess(lpProcessInformation.hProcess, lpExitCode);
TerminateProcess(lpProcessInformation.hProcess, lpExitCode);
end;