This blog post has shown us how to enumerate the running processes and services. How about monitoring a particular process in your machine? How to identify the list of threads, modules, and handles associated with a particular process programmatically? Don’t know how to do it? Don’t worry. MiTec’s System Information Management Suite’s component helps to do that effectively, and we will learn how to use the thread TSysProcMonThread to demonstrate the process monitoring.
Platforms: Windows.
Installation Steps:
You can easily install this Component Suite from GetIt Package Manager. The steps are as follows.
- Navigate In RAD Studio IDE->Tools->GetIt Package Manager->select Components in Categories->Components->Trail -MiTec system Information Component Suite 14.3 and click Install Button.
- Read the license and Click Agree All. An Information dialog saying ‘Requires a restart of RAD studio at the end of the process. Do you want to proceed? click yes and continue.
- It will download the plugin and installs it. Once installed Click Restart now.
How to run the Demo app:
- Navigate to the System Information Management Suite trails setup, Demos folder which is installed during Get It installation e.g) C:UsersDocumentsEmbarcaderoStudio21.0CatalogRepositoryMiTeC-14.3DemosDelphi18
- Open the PM project in RAD studio 10.4.1 compile and Run the application.
- This Demo App shows how to list down the running processes and its threads, handles, modules association for the selected process.
Components used in MSIC PM Demo App:
- TSysProcMonThread: Monitors system and provides running processes, CPU, memory and disk monitoring and provides system information.
- TListView for viewing running Process list.
- TPanel to show the Threads, Modules, Handles list information in a separate tab sheets for the selected process.
Implementation Details:
- An instance FSPM of TSysProcMonThread were created. And in regular interval of the thread, Process list refreshed and updated to the screen using the OnInterval Event handler. On each interval, the Process List is refreshed using RefreshProcList.
- On each interval, ThreadList, Modules List, Handles List is refreshed using procedures RefreshThreadList, RefreshModList, RefreshHandleList if a particular process is monitored.
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 |
procedure TwndMain.SYsProcMonThreadInterval(Sender: TSysProcMonThread); var p: TProcessRecord; s: string; dt: TDatetime; vi: TVersionInfo; begin RefreshProcList; Sender.GetRecordByPID(Sender.MaxCPUUsageProcessID,p); sb.Panels[1].Text:=Format('Max CPU usage: %s (%d)',[p.Name,p.PID]); if FSPM.IsProcessWatched(FRecord.PID) then begin FSPM.GetRecordByPID(FRecord.PID,FRecord); if lSigner.Tag=0 then begin if VerifyFile(FRecord.ImageName,s,dt)=0 then begin lSigner.Caption:='(Verified) '+s; lSigner.Font.Color:=clBlue; lSigner.Font.Style:=[fsUnderline]; lSigner.Cursor:=crHandPoint; end else begin GetFileVerInfo(FRecord.ImageName,vi); lSigner.Caption:='(UNVERIFIED) '+vi.CompanyName; lSigner.Font.Color:=clWindowText; lSigner.Font.Style:=[]; lSigner.Cursor:=crDefault; end; lSigner.Tag:=1; end; CPUGauge.Position:=FRecord.Performance.CPUUsage.RoundValue; lCPU.Caption:=Format('CPU Usage: %1.2f %%',[FRecord.Performance.CPUUsage.Value]); lTitle.Caption:=Format('[%d] %s (%d-bit)',[FRecord.PID,FRecord.ImageName,FRecord.Platform]); lCT.Caption:=Format('Created: %s',[DateTimeToStr(FRecord.CreationTime)]); lPri.Caption:=Format('Priority: %d',[FRecord.Priority]); lMem.Caption:=Format('Memory: %s',[NormalizeDataValue(FRecord.VMCounters.WorkingSetSize/1)]); lIORead.Caption:=Format('IO Read Rate: %s/s (Total: %s)',[NormalizeDataValue(FRecord.Performance.IOReadUsage.Delta),NormalizeDataValue(FRecord.Performance.IOReadUsage.Value)]); lIOWrite.Caption:=Format('IO Write Rate: %s/s (Total: %s)',[NormalizeDataValue(FRecord.Performance.IOWriteUsage.Delta),NormalizeDataValue(FRecord.Performance.IOWriteUsage.Value)]); tsHandles.Caption:=Format('Handles (%d/%d)',[FRecord.HandleList.Count, FRecord.HandleCount]); tsModules.Caption:=Format('Modules (%d)',[FRecord.ModuleList.Count]); RefreshThreadList; if tsModules.TabVisible and ((pc.ActivePage=tsModules) or (ModList.Items.Count=0)) then RefreshModList; if (pc.ActivePage=tsHandles) or (HandleList.Items.Count=0) then RefreshHandleList; end; end; |
In this way, you can monitor any process in your application effectively. Use this MiTeC component suite and get the job done quickly.
With the use of a Windows IDE, you can easily monitor the current Windows process in a Delphi app with a component suite. Try your Free Trial here.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Please stop “Carpet bombing” this blog with articles about your 3. party components.