VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

CPU Usage on all 32bit Windows OS

ketamine  (1 Submission)   Windows API Call/Explanation   Visual Basic 5.0   Advanced   Wed 3rd February 2021

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.

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 (8(8 Vote))

Download CPU Usage on all 32bit Windows OS

CPU Usage on all 32bit Windows OS Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters