Отображение количества оперативной памяти, которое занимает указанный процесс - VB
Формулировка задачи:
Как написать программу, которая будет показывать, сколько оперативной памяти занимает указанный процесс?
Буду благодарен.)
Решение задачи: «Отображение количества оперативной памяти, которое занимает указанный процесс»
textual
Листинг программы
- Option Explicit
- Private Declare Function NtQuerySystemInformation Lib "ntdll.dll" (ByVal infoClass As Long, Buffer As Any, ByVal BufferSize As Long, ret As Long) As Long
- Private Declare Function GetMem4 Lib "msvbvm60" (src As Any, dst As Any) As Long
- Private Declare Function GetMem8 Lib "msvbvm60" (src As Any, dst As Any) As Long
- Private Declare Sub memcpy Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
- Private Type UNICODE_STRING
- Length As Integer
- MaxLength As Integer
- lpBuffer As Long
- End Type
- Private Const SystemProcessInformation As Long = &H5&
- Private Const STATUS_INFO_LENGTH_MISMATCH As Long = &HC0000004
- Private Const STATUS_SUCCESS As Long = 0&
- Private Sub Form_Load()
- Dim ret As Long
- Dim buf() As Byte
- Dim Offset As Long
- Dim deltaOffset As Long
- Dim ImgName As UNICODE_STRING
- Dim ProcName As String
- Dim PID As Long
- Dim MemWorkSet As Long
- If NtQuerySystemInformation(SystemProcessInformation, ByVal 0&, 0&, ret) = STATUS_INFO_LENGTH_MISMATCH Then
- ReDim buf(ret - 1)
- If NtQuerySystemInformation(SystemProcessInformation, buf(0), ret, ret) = STATUS_SUCCESS Then
- Do
- GetMem8 buf(Offset + 14 * 4), ImgName
- GetMem4 buf(Offset + 17 * 4), PID
- GetMem4 buf(Offset + 26 * 4), MemWorkSet
- If PID = 0 Then
- ProcName = "System Idle Process"
- Else
- ProcName = Space$(ImgName.Length \ 2)
- memcpy ByVal StrPtr(ProcName), ByVal ImgName.lpBuffer, ImgName.Length
- End If
- Debug.Print PID
- Debug.Print ProcName
- Debug.Print Format(MemWorkSet \ 1024, "0,000") & " KB."
- GetMem4 buf(Offset), deltaOffset
- Offset = Offset + deltaOffset
- Loop While deltaOffset
- End If
- End If
- End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д