黑暗煎饼果子
执行程序函数
执行程序及启动参数, 并可选是否等待程序结束
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;
--------------------------------------------------------------------------------------------------
作者:黑暗煎饼果子
联系方式:lzl_17948876@hotmail.com
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.088858842849731 seconds