Registriert seit: 2. Jan 2006
122 Beiträge
|
Re: Windows-Pendant zu time-Befehl unter Linux
12. Apr 2008, 23:10
Ach herje, ja. Asche auf mein Haupt. Habs komplett überlesen. Aber dann implementier ich Dir halt einfach mal, das was Du willst:
Delphi-Quellcode:
program Project1;
{$APPTYPE CONSOLE}
uses
Windows, ShellAPI;
function ExecuteWaitAndTime(Filename, Params : string; var DeltaUserTime, DeltaKernelTime, DeltaExecutionTime : cardinal) : boolean;
var
ExecuteInfo: TShellExecuteInfo;
CreationTime, ExitTime, KernelTime, UserTime : _FILETIME;
begin
ZeroMemory(@ExecuteInfo, sizeof(ExecuteInfo));
with ExecuteInfo do
begin
cbSize := sizeof(ExecuteInfo);
fMask := SEE_MASK_NOCLOSEPROCESS;
lpVerb := 'open';
lpFile := PChar(Filename);
lpParameters := PChar(Params);
nShow := SW_SHOWNORMAL;
end;
if ShellExecuteEx(@ExecuteInfo) then
try
result := true;
WaitForSingleObject(ExecuteInfo.hProcess, INFINITE);
GetProcessTimes(ExecuteInfo.hProcess, CreationTime, ExitTime, KernelTime, UserTime);
DeltaExecutionTime := (Int64(ExitTime) - Int64(CreationTime)) div 10000;
DeltaUserTime := Int64(UserTime) div 10000;
DeltaKernelTime := Int64(KernelTime) div 10000;
finally
CloseHandle(ExecuteInfo.hProcess);
end
else result := false;
end;
var
ExecutionTime, UserTime, KernelTime : cardinal;
begin
writeln(ExecuteWaitAndTime('notepad.exe', '', UserTime, KernelTime, ExecutionTime));
writeln('Execution time: ', ExecutionTime);
writeln('CPU time in user mode: ', UserTime);
writeln('CPU time in kernel mode: ', KernelTime);
readln;
end.
|
|
Zitat
|