LaunchAndWait
代码
procedure LaunchAndWait(const ExeFileName: string; uCmdShow: UINT);
const
_waitTimes = 1000;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
waitCount: Cardinal;
begin
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;//If this value is not specified, the wShowWindow member is ignored.
StartupInfo.wShowWindow := uCmdShow;
CreateProcess(nil, PChar(ExeFileName), nil, nil, False, 0, nil, nil, StartupInfo, ProcessInfo);
repeat
waitCount := WaitForSingleObject(ProcessInfo.hProcess,_waitTimes);
Application.ProcessMessages;
until (waitCount <> WAIT_OBJECT_0);
if ProcessInfo.hProcess <> 0 then CloseHandle(ProcessInfo.hProcess);
if ProcessInfo.hThread <> 0 then CloseHandle(ProcessInfo.hThread);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
LaunchAndWait('D:\windows\notepad.exe',SW_NORMAL);
end;