如何在Win中捕獲應用程序(進程)的啓動和完成。 如何測量每個應用程序的時間?捕獲啓動應用程序
Q
捕獲啓動應用程序
1
A
回答
2
有幾個或幾個Windows API調用名稱中的「鉤子」,允許您捕獲系統級事件。您必須將這些內容構建到DLL中,然後從單獨的應用程序調用「掛鉤」DLL。
那很簡單,就是這樣。希望能讓你開始!
3
您可以使用GetProcessTimes函數獲取特定進程的計時信息。
BOOL WINAPI GetProcessTimes(
__in HANDLE hProcess,
__out LPFILETIME lpCreationTime,
__out LPFILETIME lpExitTime,
__out LPFILETIME lpKernelTime,
__out LPFILETIME lpUserTime
);
見這個例子
program GetProcessTime;
{$APPTYPE CONSOLE}
uses
DateUtils,
Windows,
tlhelp32,
SysUtils;
Procedure GetAllProcessTime;
var
HandleSnapShot : THandle;
EntryParentProc : TProcessEntry32;
DummyCreateFileTime : Windows.FILETIME;
DummyExitFileTime : Windows.FILETIME;
DummyKernelFileTime : Windows.FILETIME;
DummyUserFileTime : Windows.FILETIME;
aFileName : String;
h : THandle;
ActualTime : TDateTime;
Dif : TDateTime;
CreationTime : TDateTime;
function FileTime2DateTime(FileTime: TFileTime): TDateTime; //Convert then FileTime to TDatetime format
var
LocalTime: TFileTime;
DOSTime : Integer;
begin
FileTimeToLocalFileTime(FileTime, LocalTime);
FileTimeToDosDateTime(LocalTime, LongRec(DOSTime).Hi, LongRec(DOSTime).Lo);
Result := FileDateToDateTime(DOSTime);
end;
begin
HandleSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //get the list of process
if HandleSnapShot <> INVALID_HANDLE_VALUE then
begin
EntryParentProc.dwSize := SizeOf(EntryParentProc);
if Process32First(HandleSnapShot, EntryParentProc) then //Get the first process in the list
begin
Writeln(Format('%-30s %-20s %-16s',['FileName','Start','Running Time']) );
ActualTime:=Now;
repeat
h:=OpenProcess(PROCESS_QUERY_INFORMATION,false,EntryParentProc.th32ProcessID); //open a particular process
if GetProcessTimes(h, DummyCreateFileTime, DummyExitFileTime, DummyKernelFileTime, DummyUserFileTime) then //get the timing info
begin
aFileName:=ExtractFileName(EntryParentProc.szExeFile);
CreationTime:=FileTime2DateTime(DummyCreateFileTime); //get the initial time of the process
Dif := ActualTime-CreationTime; //calculate the elapsed time
Writeln(Format('%-30s %-20s %-16s',[aFileName,FormatDateTime('DD-MM-YYYY HH:NN:SS',CreationTime),FormatDateTime('HH:NN:SS',Dif)]) );
end;
CloseHandle(h);
until not Process32Next(HandleSnapShot, EntryParentProc);
end;
CloseHandle(HandleSnapShot);
end;
end;
begin
try
GetAllProcessTime();
Readln;
except
on E: Exception do
begin
Writeln(E.ClassName, ': ', E.Message);
Readln;
end;
end;
end.
1
的WH_CBT hook是最有可能的一個你是後。它允許您在創建或銷燬窗口時通知操作系統。您將希望使用此掛鉤來抓取手柄,並從手柄獲取使用GetWindowThreadProcessId的進程ID。然後,您可以將此句柄傳遞給函數GetProcessTimes(由RRUZ建議)以獲得時間。一個示例(儘管過時,概念仍然相同)可在GpSysHook源文件中找到。
1
Windows Performance Analyzer具有專門用於計時應用程序的功能,即使它們處於啓動或登錄順序,也可以從啓動時開始計時。
1
Windows Management Instrumentation提供事件訂閱。 WMI的好處在於它使用DCOM和SOAP也可以工作在遠程。
WMI offers the capability to notify a subscriber for any event it is interested in.
WMI使用WMI查詢語言(WQL) 提交WQL事件查詢和 定義的事件類型是 返回。所有相關回調的事件機制 WMI COM/DCOM和自動化接口 的一部分。
德爾福的免費WMI客戶端實現可在網上(如果它支持事件回調不知道):
相關問題
- 1. 在應用程序啓動時捕獲異常(VS.Net)
- 2. Android應用程序無法啓動未捕獲的異常
- 3. 如何捕獲服務中的應用程序啓動?
- 4. 當應用程序啓動時捕獲窗口創建消息
- 5. 獲取應用程序啓動方法
- 6. 在應用程序啓動時啓動應用程序類
- 7. 從應用程序啓動「啓動器應用程序抽屜」?
- 8. 捕捉Android應用程序啓動和應用程序最小化事件
- 9. 如何在新流程(應用程序!)啓動時捕獲事件?
- 10. 啓動應用程序在啓動時
- 11. 在啓動時啓動應用程序
- 12. 在啓動時啓動應用程序
- 13. 獲取應用程序以啓動啓動
- 14. 獲取啓動器啓動的應用程序的上下文
- 15. 如何捕捉用於啓動應用程序的意圖?
- 16. 自動阻止應用程序從啓動程序啓動
- 17. 啓動主應用程序
- 18. 啓動應用程序
- 19. 在應用程序啓動
- 20. Android應用程序啓動
- 21. 在啓動應用程序
- 22. Grails啓動應用程序
- 23. 應用程序不啓動?
- 24. 而應用程序啓動
- 25. 應用程序啓動器
- 26. 啓動Android應用程序
- 27. 在應用程序啓動
- 28. 當應用程序啓動
- 29. 應用程序不啓動
- 30. 啓動應用程序