执行程序函数
执行程序及启动参数, 并可选是否等待程序结束
function RunApp(AApp, AParams: String; AWaitFor: Boolean): DWORD; var nSI: TSTARTUPINFO; nPI: TPROCESSINFORMATION; nR: Boolean; begin Result := 0; with nSI do begin cb := Sizeof(TSTARTUPINFO); lpReserved := nil; lpDesktop := nil; lpTitle := nil; dwFlags := STARTF_USESHOWWINDOW and STARTF_USESTDHANDLES; cbReserved2 := 0; lpReserved2 := nil; end; nR := CreateProcess(PChar(AApp), PChar(AParams), nil, nil, True, CREATE_DEFAULT_ERROR_MODE and NORMAL_PRIORITY_CLASS, nil, PChar(ExtractFilePath(AApp)), nSI, nPI); if nR then { 等待结束 } begin if AWaitFor then begin Result := 1; WaitForSingleObject(nPI.hProcess, INFINITE); CloseHandle(nPI.hProcess); { 清理句柄 } CloseHandle(nPI.hThread); end else Result := nPI.dwProcessId; end; end;
--------------------------------------------------------------------------------------------------
作者:黑暗煎饼果子
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
--------------------------------------------------------------------------------------------------