模态运行EXE程序

function ExecShowModal(APath: PChar; ACmdShow: Integer; ATimeout: Longword): Integer;

var

  vStartupInfo: TStartupInfo;

  vProcessInfo: TProcessInformation;

begin

  FillChar(vStartupInfo, SizeOf(TStartupInfo), 0);

  with vStartupInfo do

  begin

    cb := SizeOf(TStartupInfo);

    dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;

    wShowWindow := ACmdShow;

  end;

  if CreateProcess(nil, APath, nil, nil, False,

    NORMAL_PRIORITY_CLASS, nil, nil,

    vStartupInfo, vProcessInfo) then

    Result := WaitForSingleObject(vProcessInfo.hProcess, ATimeout)

  else Result := GetLastError;

end;







procedure TForm1.Button3Click(Sender: TObject);

begin

  ExecShowModal('notepad.exe', SW_SHOW, INFINITE);

end;
View Code

 

你可能感兴趣的:(exe)