VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



CPU Usage on all 32bit Windows OS

by ketamine (1 Submission)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (7 Votes)

A simple to use class that returns the current CPU load usage of the system as a percentage. Works with all 32bit Windows operating systems (9x, ME, NT, 2000, XP) and also works with multiple processors.
I couldn't find any CPU usage code on VBC that would work with XP, so I had a hunt around the web and came across the NtQuerySystemInformation API.
The class detects the OS and uses the appropriate CPU usage retrieval system.

Assumes
Developers should find this class straight-forward to use. Let me know if you have any dfficulties.
Code Returns
CurrentCPUUsage As Long (percentage of current CPU loading)
API Declarations
Private Declare Function NtQuerySystemInformation Lib "ntdll" (ByVal dwInfoType As Long, ByVal lpStructure As Long, ByVal dwSize As Long, ByVal dwReserved As Long) As Long
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function GetVersionEx Lib "KERNEL32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Rate CPU Usage on all 32bit Windows OS

Download CPU Usage on all 32bit Windows OS

Download CPU Usage on all 32bit Windows OS (3 KB)

CPU Usage on all 32bit Windows OS Comments

No comments have been posted about CPU Usage on all 32bit Windows OS. Why not be the first to post a comment about CPU Usage on all 32bit Windows OS.

Post your comment

Subject:
Message:
0/1000 characters