Results 1 to 6 of 6

Thread: Monitoring Windows (CPU, Memory, etc.)

  1. #1

    Thread Starter
    Addicted Member imbue's Avatar
    Join Date
    Aug 2002
    Location
    Midwest USA
    Posts
    155

    Question Monitoring Windows (CPU, Memory, etc.)

    I am looking for an easy way to get system information much like what the system monitor (found under accessories\system tools) in Windows does.

    I would like to be able to find the
    CPU load
    Allocated Memory
    bytes read/written to filesystem/second
    bytes sent/received from internet/second (or network)

    If you know how to do any/all of these from VB please tell me.

    Thanks

  2. #2
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Here's a start

    see attached
    Attached Files Attached Files

  3. #3
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327
    I was wondering the same thing a couple of months ago. Can you give part of the code? I cant download right now for a few days.
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  4. #4
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    NmodAPIMemory.bas
    Code:
    Option Explicit
    
    'TYPE DECLARATIONS
    Public Type MEMORYSTATUS
        dwLength As Long
        dwMemoryLoad As Long
        dwTotalPhys As Long
        dwAvailPhys As Long
        dwTotalPageFile As Long
        dwAvailPageFile As Long
        dwTotalVirtual As Long
        dwAvailVirtual As Long
    End Type
    
    
    'API CONSTANTS
    
    
    'API DLL FUNCTION DECLARATIONS
    Public Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
    NmodWindow.bas
    Code:
    Option Explicit
    
    'API CONSTANTS
    Private Const SWP_NOMOVE = 2
    Private Const SWP_NOSIZE = 1
    Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    
    'API DLL FUNCTION DECLARATIONS
    Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, _
        ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
        ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Public Sub WindowOnTop(lngHwindow As Long)
        SetWindowPos lngHwindow, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
    End Sub
    frmMain.frm
    Code:
    Option Explicit
    
    Private Function GetFileSizeStr(dblSize As Double) As String
    'returns a string of the number supplied, in bytes kb etc, whichever is more appropriate
        Const cKB = 1024
        Const cMB = 1048576
        Const cGB = 1073741824
    
        If dblSize <= 1024 Then
            GetFileSizeStr = dblSize & " Bytes"
        ElseIf dblSize <= cMB Then
            GetFileSizeStr = Format(dblSize / cKB, "0.00 Kb")
        ElseIf dblSize <= cGB Then
            GetFileSizeStr = Format(dblSize / cMB, "0.00 Mb")
        Else
            GetFileSizeStr = Format(dblSize / cGB, "0.00 Gb")
        End If
    End Function
    
    Private Sub cmdMinimise_Click()
        Me.WindowState = vbMinimized
    End Sub
    
    Private Sub Form_Load()
        WindowOnTop Me.hWnd
    End Sub
    
    Private Sub Timer1_Timer()
    On Error GoTo ErrorHandler
    
        Dim mem As MEMORYSTATUS
        
        'Get memory info update
        GlobalMemoryStatus mem
        
        lblRAMTotal.Caption = GetFileSizeStr(CDbl(mem.dwTotalPhys))
        lblRAMUsed.Caption = GetFileSizeStr(CDbl(mem.dwTotalPhys - mem.dwAvailPhys))
        lblRAMAvailable.Caption = GetFileSizeStr(CDbl(mem.dwAvailPhys))
        lblPFTotal.Caption = GetFileSizeStr(CDbl(mem.dwTotalPageFile))
        lblPFUsed.Caption = GetFileSizeStr(CDbl(mem.dwTotalPageFile - mem.dwAvailPageFile))
        lblPFAvailable.Caption = GetFileSizeStr(CDbl(mem.dwAvailPageFile))
        lblVRAMTotal.Caption = GetFileSizeStr(CDbl(mem.dwTotalVirtual))
        lblVRAMUsed.Caption = GetFileSizeStr(CDbl(mem.dwTotalVirtual - mem.dwAvailVirtual))
        lblVRAMAvailable.Caption = GetFileSizeStr(CDbl(mem.dwAvailVirtual))
        Me.Caption = "(" & Format(mem.dwAvailPhys / mem.dwTotalPhys, "0%") & ") " & lblRAMAvailable.Caption & " RAM Available"
        
    CleanUp:
        Exit Sub
        
    ErrorHandler:
        MsgBox Err.Description, , Err.Number
        Resume CleanUp
    End Sub

  5. #5

    Thread Starter
    Addicted Member imbue's Avatar
    Join Date
    Aug 2002
    Location
    Midwest USA
    Posts
    155

    GREAT

    that should work great! Thanks Briantcva.

    I still need to figure
    CPU load
    bytes read/written to filesystem/second
    bytes sent/received from internet/second (or network)

    so if anyone has code for this please post it here.

  6. #6

    Thread Starter
    Addicted Member imbue's Avatar
    Join Date
    Aug 2002
    Location
    Midwest USA
    Posts
    155
    any more ideas?

    Does anyone know how System Monitor goes about getting this information?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width