1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
function BuildDosCommandStr(Command:string):string;
begin
result:='cmd /c "'+Command+'"';
end;
function ExecuteCommande(Commande: String;Attente : Boolean = True): Boolean;
Var
lpsaProcess,
lpsaThread : PSecurityAttributes;
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
AddrCmd : Array [0..255] Of Char;
ExitCode : DWord;
begin
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
with StartupInfo do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
wShowWindow := SW_HIDE;
end;
New(lpsaProcess);
New(lpsaThread);
lpsaProcess^.nLength := SizeOf(lpsaProcess^);
lpsaProcess^.lpSecurityDescriptor := Nil;
lpsaProcess^.bInheritHandle := True;
lpsaThread^.nLength := SizeOf(lpsaThread^);
lpsaThread^.lpSecurityDescriptor := Nil;
lpsaThread^.bInheritHandle := True;
StrPCopy(AddrCmd, Commande);
Result := CreateProcess(nil, AddrCmd, lpsaProcess, lpsaThread, False,
STARTF_FORCEONFEEDBACK, nil, nil, StartupInfo, ProcessInfo);
if not Result then Result:=(GetLastError>10000);
Dispose(lpsaProcess);
Dispose(lpsaThread);
if Result then
begin
while Attente do
begin
// Solution d'attente 1
Sleep(500);
GetExitCodeProcess(ProcessInfo.hProcess, ExitCode);
if ExitCode<>STILL_ACTIVE then break;
// Solution d'attente 2
// WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
end;
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
end;
end; |
Partager