Код не мой, где-то взял (может даже на этом сайте - не помню ( ) В проэкт добавь класмодуль. Name = CPULoad В него этот код: ____________________________ Option Explicit Private Const ClassName As String = "CPULoad" Private Const Err_Initialize As Long = vbObjectError + 8001 Private Const Err_UnableToStartPerfmon As Long = vbObjectError + 8002 Private Const Err_CPUIndexOOB As Long = vbObjectError + 8003 Private Const Err_CantFindProcessorPerfMon As Long = vbObjectError + 8004 Private Const Err_CantFindCPUUsagePerfMon As Long = vbObjectError + 8005 Private Const Err_UnableToReadPDB As Long = vbObjectError + 8006 Private Declare Sub Memcopy Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long) Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SystemTime, lpFileTime As Currency) 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 Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO) Private Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKey As Long) As Long Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private Type SYSTEM_INFO dwOemID As Long dwPageSize As Long lpMinimumApplicationAddress As Long lpMaximumApplicationAddress As Long dwActiveProcessorMask As Long dwNumberOrfProcessors As Long dwProcessorType As Long dwAllocationGranularity As Long dwReserved As Long End Type Private Const HKEY_DYN_DATA = &H80000006 Private Const HKEY_PERFORMANCE_DATA = &H80000004 Private Const REG_DWORD = 4 Private Const ERROR_SUCCESS = 0& Private Const ERROR_MORE_DATA = 234 Private Const VER_PLATFORM_WIN32_NT = 2 Private Const VER_PLATFORM_WIN32_WINDOWS = 1 Private Const VER_PLATFORM_WIN32s = 0 Private Const READ_CONTROL = &H20000 Private Const STANDARD_RIGHTS_READ = (READ_CONTROL) Private Const KEY_QUERY_VALUE = &H1 Private Const KEY_SET_VALUE = &H2 Private Const KEY_CREATE_SUB_KEY = &H4 Private Const KEY_ENUMERATE_SUB_KEYS = &H8 Private Const KEY_NOTIFY = &H10 Private Const KEY_CREATE_LINK = &H20 Private Const SYNCHRONIZE = &H100000 Private Const STANDARD_RIGHTS_ALL = &H1F0000 Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _ KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _ KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _ KEY_CREATE_LINK) And (Not SYNCHRONIZE)) Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or _ KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE)) Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Type SystemTime wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type Private Type LARGE_INTEGER lowpart As Long highpart As Long End Type Private Type PERF_INSTANCE_DEFINITION ByteLength As Long ParentObjectTitleIndex As Long ParentObjectInstance As Long UniqueID As Long NameOffset As Long NameLength As Long End Type Private Type PERF_COUNTER_BLOCK ByteLength As Long End Type Private Type PERF_DATA_BLOCK Signature As String * 4 LittleEndian As Long Version As Long Revision As Long TotalByteLength As Long HeaderLength As Long NumObjectTypes As Long DefaultObject As Long SystemTime As SystemTime PerfTime As LARGE_INTEGER PerfFreq As LARGE_INTEGER PerTime100nSec As LARGE_INTEGER SystemNameLength As Long SystemNameOffset As Long End Type Private Type PERF_OBJECT_TYPE TotalByteLength As Long DefinitionLength As Long HeaderLength As Long ObjectNameTitleIndex As Long ObjectNameTitle As Long ObjectHelpTitleIndex As Long ObjectHelpTitle As Long DetailLevel As Long NumCounters As Long DefaultCounter As Long NumInstances As Long CodePage As Long PerfTime As LARGE_INTEGER PerfFreq As LARGE_INTEGER End Type Private Type PERF_COUNTER_DEFINITION ByteLength As Long CounterNameTitleIndex As Long CounterNameTitle As Long CounterHelpTitleIndex As Long
Ответить
|