home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / SysMon_wit2155896252009.psc / ClassPMonCPU.cls < prev    next >
Text File  |  2009-06-25  |  18KB  |  530 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "ClassPMonCPU"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. Private Const ClassName As String = "CPULoad"
  17.  
  18. Private Const Err_Initialize As Long = vbObjectError + 8001
  19. Private Const Err_UnableToStartPerfmon As Long = vbObjectError + 8002
  20. Private Const Err_CPUIndexOOB As Long = vbObjectError + 8003
  21. Private Const Err_CantFindProcessorPerfMon As Long = vbObjectError + 8004
  22. Private Const Err_CantFindCPUUsagePerfMon As Long = vbObjectError + 8005
  23. Private Const Err_UnableToReadPDB As Long = vbObjectError + 8006
  24.  
  25.  
  26.  
  27.  
  28. Private Declare Sub Memcopy Lib "KERNEL32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
  29.  
  30. Private Declare Function SystemTimeToFileTime Lib "KERNEL32" (lpSystemTime As SystemTime, lpFileTime As Currency) As Long
  31. Private Declare Function GetVersionEx Lib "KERNEL32" Alias "GetVersionExA" (LpVersionInformation As OSVERSIONINFO) As Long
  32. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  33. 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
  34. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  35.  
  36. 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
  37.  
  38. Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
  39.  
  40. Private Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
  41.  
  42.  
  43. Private Declare Sub GetSystemInfo Lib "KERNEL32" (lpSystemInfo As SYSTEM_INFO)
  44.  
  45.  
  46.  
  47. Private Type SYSTEM_INFO
  48.     dwOemID As Long
  49.     dwPageSize As Long
  50.     lpMinimumApplicationAddress As Long
  51.     lpMaximumApplicationAddress As Long
  52.     dwActiveProcessorMask As Long
  53.     dwNumberOrfProcessors As Long
  54.     dwProcessorType As Long
  55.     dwAllocationGranularity As Long
  56.     dwReserved As Long
  57. End Type
  58.  
  59. Private Const HKEY_LOCAL_MACHINE = &H80000002
  60.  
  61. Private Const HKEY_PERFORMANCE_DATA = &H80000004
  62. Private Const REG_DWORD = 4
  63. Private Const ERROR_SUCCESS = 0&
  64. Private Const ERROR_MORE_DATA = 234
  65.  
  66. Private Type OSVERSIONINFO
  67.     dwOSVersionInfoSize As Long
  68.     dwMajorVersion As Long
  69.     dwMinorVersion As Long
  70.     dwBuildNumber As Long
  71.     dwPlatformID As Long
  72.     szCSDVersion As String * 128
  73. End Type
  74.  
  75. Private Const VER_PLATFORM_WIN32_NT = 2
  76. Private Const VER_PLATFORM_WIN32_WINDOWS = 1
  77. Private Const VER_PLATFORM_WIN32s = 0
  78.  
  79. Private Const READ_CONTROL = &H20000
  80. Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
  81. Private Const KEY_QUERY_VALUE = &H1
  82. Private Const KEY_SET_VALUE = &H2
  83. Private Const KEY_CREATE_SUB_KEY = &H4
  84. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
  85. Private Const KEY_NOTIFY = &H10
  86. Private Const KEY_CREATE_LINK = &H20
  87. Private Const SYNCHRONIZE = &H100000
  88. Private Const STANDARD_RIGHTS_ALL = &H1F0000
  89.  
  90. Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
  91.                                 KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _
  92.                                 KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
  93.                                 KEY_CREATE_LINK) And (Not SYNCHRONIZE))
  94.  
  95. Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or _
  96.                         KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  97.  
  98. Private Type FILETIME
  99.     dwLowDateTime As Long
  100.     dwHighDateTime As Long
  101. End Type
  102.  
  103. Private Type SystemTime
  104.     wYear As Integer
  105.     wMonth As Integer
  106.     wDayOfWeek As Integer
  107.     wDay As Integer
  108.     wHour As Integer
  109.     wMinute As Integer
  110.     wSecond As Integer
  111.     wMilliseconds As Integer
  112. End Type
  113.  
  114. Private Type LARGE_INTEGER
  115.     lowpart As Long
  116.     highpart As Long
  117. End Type
  118.  
  119. Private Type PERF_INSTANCE_DEFINITION
  120.     ByteLength As Long
  121.     ParentObjectTitleIndex As Long
  122.     ParentObjectInstance As Long
  123.     UniqueID As Long
  124.     NameOffset As Long
  125.     NameLength As Long
  126. End Type
  127.  
  128. Private Type PERF_COUNTER_BLOCK
  129.     ByteLength As Long
  130. End Type
  131.  
  132. Private Type PERF_DATA_BLOCK
  133.     Signature As String * 4
  134.     LittleEndian As Long
  135.     Version As Long
  136.     Revision As Long
  137.     TotalByteLength As Long
  138.     HeaderLength As Long
  139.     NumObjectTypes As Long
  140.     DefaultObject As Long
  141.     SystemTime As SystemTime
  142.     PerfTime As LARGE_INTEGER
  143.     PerfFreq As LARGE_INTEGER
  144.     PerTime100nSec As LARGE_INTEGER
  145.     SystemNameLength As Long
  146.     SystemNameOffset As Long
  147. End Type
  148.  
  149. Private Type PERF_OBJECT_TYPE
  150.     TotalByteLength As Long
  151.     DefinitionLength As Long
  152.     HeaderLength As Long
  153.     ObjectNameTitleIndex As Long
  154.     ObjectNameTitle As Long
  155.     ObjectHelpTitleIndex As Long
  156.     ObjectHelpTitle As Long
  157.     DetailLevel As Long
  158.     NumCounters As Long
  159.     DefaultCounter As Long
  160.     NumInstances As Long
  161.     CodePage As Long
  162.     PerfTime As LARGE_INTEGER
  163.     PerfFreq As LARGE_INTEGER
  164. End Type
  165.  
  166. Private Type PERF_COUNTER_DEFINITION
  167.     ByteLength As Long
  168.     CounterNameTitleIndex As Long
  169.     CounterNameTitle As Long
  170.     CounterHelpTitleIndex As Long
  171.     CounterHelpTitle As Long
  172.     DefaultScale As Long
  173.     DetailLevel As Long
  174.     CounterType As Long
  175.     CounterSize As Long
  176.     CounterOffset As Long
  177. End Type
  178.  
  179. Private Const Processor_IDX_Str As String = "238"
  180. Private Const Processor_IDX  As Long = 238
  181. Private Const CPUUsageIDX As Long = 6
  182.  
  183.  
  184. Private Const RAM_IDX_str = "4"
  185. Private Const RAM_IDX = 4
  186. Private Const RamRemain_IDX = 24
  187.  
  188.  
  189. Private m_lProcessorsCount As Long
  190. Private m_lBufferSizeCPU As Long
  191. Private m_lBufferSizeRAM As Long
  192. Private m_bIsWinNT As Boolean
  193.  
  194.  
  195.  
  196. Private PDB_CPU As PERF_DATA_BLOCK
  197. Private POT_CPU As PERF_OBJECT_TYPE
  198. Private PCD_CPU As PERF_COUNTER_DEFINITION
  199. Private PID_CPU As PERF_INSTANCE_DEFINITION
  200. Private PCB_CPU As PERF_COUNTER_BLOCK
  201.  
  202. 'Private PDB_RAM As PERF_DATA_BLOCK
  203. 'Private POT_RAM As PERF_OBJECT_TYPE
  204. 'Private PCD_RAM As PERF_COUNTER_DEFINITION
  205. 'Private PID_RAM As PERF_INSTANCE_DEFINITION
  206. 'Private PCB_RAM As PERF_COUNTER_BLOCK
  207. '
  208. 'Private VI As OSVERSIONINFO
  209.  
  210. Private SysTime As Currency
  211. Private PrevSysTime As Currency
  212. Private m_aCountersCPU() As Currency
  213. Private m_aPrevCountersCPU() As Currency
  214. Private m_aCountersRAM As Currency
  215. Private m_aPrevCountersRAM As Currency
  216.  
  217. Private Const BYTEIncrement As Long = 4096
  218.  
  219. Private m_bConnected As Boolean
  220. Private m_regHandleRemote As Long
  221. Private m_sMachine As String
  222.  
  223. '//*************************************************************
  224. Private mvar_RemoteServer As String
  225. Private m_bLocalServer As Boolean
  226. Public Property Let RemoteServer(ByVal NewData As String)
  227.     If Len(NewData) Then
  228.         If Left(NewData, 2) = "\\" Then
  229.             mvar_RemoteServer = NewData
  230.         Else
  231.             mvar_RemoteServer = "\\" & NewData
  232.         End If
  233.         m_bLocalServer = True
  234.     Else
  235.         m_bLocalServer = False
  236.     End If
  237. End Property
  238. '//*************************************************************
  239.  
  240.  
  241. Private Sub Class_Initialize()
  242.  
  243.  
  244.     m_lProcessorsCount = -1
  245.     m_lBufferSizeCPU = BYTEIncrement
  246.     m_lBufferSizeRAM = BYTEIncrement
  247. End Sub
  248.  
  249. Private Sub Class_Terminate()
  250.     '
  251. End Sub
  252.  
  253. Public Function CollectCPUData() As Boolean
  254. Dim lKeyRegistry As Long, lResReg As Long
  255. Dim H As Long, r As Long
  256. Dim aBuf() As Byte, lAllocSz As Long
  257. Dim lSrc As Long, lDest As Long
  258. Dim ptrPOT As Long, ptrPCB As Long
  259. Dim i As Long, lCPU As Long
  260. Dim ST As Currency
  261. Dim sInstanceName As String
  262.         If m_bLocalServer Then
  263.             lResReg = RegConnectRegistry(mvar_RemoteServer, HKEY_PERFORMANCE_DATA, lKeyRegistry)
  264.             If lResReg <> 0 Then
  265.                 CollectCPUData = -1
  266.                 Exit Function
  267.             End If
  268.         Else
  269.             lKeyRegistry = HKEY_PERFORMANCE_DATA
  270.         End If
  271.     
  272.         lAllocSz = m_lBufferSizeCPU
  273.         ReDim aBuf(1 To lAllocSz) As Byte
  274.         'While RegQueryValueEx(HKEY_PERFORMANCE_DATA, Processor_IDX_Str, 0, 0, aBuf(1), m_lBufferSizeCPU) = ERROR_MORE_DATA
  275.         While RegQueryValueEx(lKeyRegistry, Processor_IDX_Str, 0, 0, aBuf(1), m_lBufferSizeCPU) = ERROR_MORE_DATA
  276.             lAllocSz = lAllocSz + BYTEIncrement
  277.             ReDim aBuf(1 To lAllocSz) As Byte
  278.             m_lBufferSizeCPU = lAllocSz
  279.         Wend
  280.  
  281.         lDest = VarPtr(PDB_CPU)
  282.         lSrc = VarPtr(aBuf(1))
  283.         Memcopy ByVal lDest, ByVal lSrc, LenB(PDB_CPU)
  284.         m_lBufferSizeCPU = lAllocSz
  285.         If PDB_CPU.Signature <> "PERF" Then
  286.             Err.Raise Err_UnableToReadPDB, ClassName & ".CollectCPUData()", "Unable to read performance data"
  287.         End If
  288.         lDest = VarPtr(POT_CPU)
  289.         lSrc = VarPtr(aBuf(1)) + PDB_CPU.HeaderLength
  290.         For i = 1 To PDB_CPU.NumObjectTypes
  291.             Memcopy ByVal lDest, ByVal lSrc, LenB(POT_CPU)
  292.             ptrPOT = lSrc
  293.             If POT_CPU.ObjectNameTitleIndex = Processor_IDX Then Exit For
  294.             lSrc = lSrc + POT_CPU.TotalByteLength
  295.         Next i
  296.         
  297.         
  298.         If POT_CPU.ObjectNameTitleIndex <> Processor_IDX Then
  299.             Err.Raise Err_CantFindProcessorPerfMon, ClassName & ".CollectData", "Unable to locate the 'Processor' performance object"
  300.         End If
  301.         If m_lProcessorsCount < 1 Then
  302.             m_lProcessorsCount = GetCPUCount()
  303.         End If
  304.         lDest = VarPtr(PCD_CPU)
  305.         lSrc = lSrc + POT_CPU.HeaderLength
  306.         For i = 1 To POT_CPU.NumCounters
  307.             Memcopy ByVal lDest, ByVal lSrc, LenB(PCD_CPU)
  308.             If PCD_CPU.CounterNameTitleIndex = CPUUsageIDX Then Exit For
  309.             lSrc = lSrc + PCD_CPU.ByteLength
  310.         Next i
  311.         If PCD_CPU.CounterNameTitleIndex <> CPUUsageIDX Then
  312.             Err.Raise Err_CantFindCPUUsagePerfMon, ClassName & ".CollectData", "Unable to locate the '% of CPU usage' performance counter"
  313.         End If
  314.         
  315.         
  316.         lSrc = ptrPOT + POT_CPU.DefinitionLength
  317.         For i = 1 To POT_CPU.NumInstances
  318.             lDest = VarPtr(PID_CPU)
  319.             Memcopy ByVal lDest, ByVal lSrc, LenB(PID_CPU)
  320.             sInstanceName = Space(PID_CPU.NameLength - 2)
  321.             Memcopy ByVal sInstanceName, ByVal lSrc + PID_CPU.NameOffset, PID_CPU.NameLength - 2
  322.             
  323.             sInstanceName = StrConv(sInstanceName, vbFromUnicode)
  324.  
  325.             lSrc = lSrc + PID_CPU.ByteLength
  326.             lDest = VarPtr(PCB_CPU)
  327.             Memcopy ByVal lDest, ByVal lSrc, LenB(PCB_CPU)
  328.             ptrPCB = lSrc
  329.             If IsNumeric(sInstanceName) Then
  330.                 lCPU = CLng(sInstanceName)
  331.                 m_aPrevCountersCPU(lCPU) = m_aCountersCPU(lCPU)
  332.                 Memcopy ByVal VarPtr(m_aCountersCPU(lCPU)), ByVal ptrPCB + PCD_CPU.CounterOffset, LenB(m_aCountersCPU(lCPU))
  333.             End If
  334.  
  335.             lSrc = lSrc + PCB_CPU.ByteLength
  336.         Next i
  337.         PrevSysTime = SysTime
  338.         SystemTimeToFileTime PDB_CPU.SystemTime, ST
  339.         SysTime = ST
  340.         
  341.     RegCloseKey lKeyRegistry
  342. End Function
  343.  
  344. Public Function GetPerfDataValue(sInstance As String, sValue As String) As Currency
  345. Dim H As Long, r As Long
  346. Dim aBuf() As Byte, lAllocSz As Long, lBufSize As Long
  347. Dim lSrc As Long, lDest As Long
  348. Dim ptrPOT As Long, ptrPCB As Long
  349. Dim i As Long, j As Long, k As Long
  350. Dim ST As Currency
  351. Dim perfDataBlock As PERF_DATA_BLOCK
  352. Dim perfObjectType As PERF_OBJECT_TYPE
  353. Dim perfCtrDef As PERF_COUNTER_DEFINITION
  354. Dim perfInstDef As PERF_INSTANCE_DEFINITION
  355. Dim PerfCounterDef As PERF_COUNTER_DEFINITION
  356.  
  357.         lBufSize = BYTEIncrement
  358.         lAllocSz = lBufSize
  359.         ReDim aBuf(1 To lAllocSz) As Byte
  360.         '//BaseObject
  361.         While RegQueryValueEx(m_regHandleRemote, sInstance, 0, 0, aBuf(1), lBufSize) = ERROR_MORE_DATA
  362.             lAllocSz = lAllocSz + BYTEIncrement
  363.             ReDim aBuf(1 To lAllocSz) As Byte
  364.             lBufSize = lAllocSz
  365.         Wend
  366.         
  367.         lDest = VarPtr(perfDataBlock)
  368.         lSrc = VarPtr(aBuf(1))
  369.         Memcopy ByVal lDest, ByVal lSrc, LenB(perfDataBlock)
  370.         'lBufSize = lAllocSz
  371.         
  372.         
  373.         '// check for success and valid perf data block signature
  374.         If perfDataBlock.Signature <> "PERF" Then
  375.             Debug.Print "Cannot Get Datablock"
  376.         End If
  377.         
  378.         lDest = VarPtr(perfObjectType)
  379.         lSrc = VarPtr(aBuf(1)) + perfDataBlock.HeaderLength
  380.         '//Verify Baseobject
  381.         For i = 1 To perfDataBlock.NumObjectTypes
  382.             Memcopy ByVal lDest, ByVal lSrc, LenB(perfObjectType)
  383.             ptrPOT = lSrc
  384.             If perfObjectType.ObjectNameTitleIndex = sInstance Then Exit For
  385.             
  386.             lSrc = lSrc + perfObjectType.TotalByteLength
  387.         Next i
  388.         
  389.         
  390.         If perfObjectType.ObjectNameTitleIndex <> sInstance Then
  391.             'Err.Raise Err_CantFindProcessorPerfMon, ClassName & ".CollectData", "Unable to locate the 'RAM' performance object"
  392.             Debug.Print "No result"
  393.         End If
  394.         '//Here we are, we found our Subcounter
  395.         lSrc = lSrc + perfObjectType.HeaderLength
  396.         lDest = VarPtr(PerfCounterDef)
  397.         For i = 1 To perfObjectType.NumCounters
  398.             
  399.             Memcopy lDest, lSrc, LenB(PerfCounterDef)
  400.             '//We found or Value of Interrest
  401.             If PerfCounterDef.CounterNameTitleIndex = sValue Then
  402.                 Debug.Print
  403.                 Exit For
  404.             Else
  405.                 lSrc = lSrc + PerfCounterDef.ByteLength
  406.             End If
  407.         Next
  408.         
  409. End Function
  410.  
  411.  
  412. '  PERF_DATA_BLOCK
  413. '    PERF_OBJECT_TYPE (1)
  414. '      PERF_COUNTER_DEFINITION (1)
  415. '      PERF_COUNTER_DEFINITION (2)
  416. '      <...>
  417. '      PERF_INSTANCE_DEFINITION (1)
  418. '        PERF_COUNTER_BLOCK
  419. '          counterData1
  420. '          counterData2
  421. '          counterData3
  422. '          <...>
  423. '      PERF_INSTANCE_DEFINITION (2)
  424. '        PERF_COUNTER_BLOCK
  425. '          counterData1
  426. '          counterData2
  427. '          counterData3
  428. '          <...>
  429. '    PERF_OBJECT_TYPE (2)
  430. '    <...>
  431.  
  432.  
  433. 'Public Function GetCPUCountLocal() As Long
  434. 'Dim SI As SYSTEM_INFO
  435. '
  436. '    If m_lProcessorsCount < 1 Then
  437. '        GetSystemInfo SI
  438. '        GetCPUCountLocal = SI.dwNumberOrfProcessors
  439. '        m_lProcessorsCount = SI.dwNumberOrfProcessors
  440. '        'm_lProcessorsCount = 1
  441. '        ReDim m_aPrevCountersCPU(0 To m_lProcessorsCount - 1) As Currency
  442. '        ReDim m_aCountersCPU(0 To m_lProcessorsCount - 1) As Currency
  443. '    Else
  444. '        GetCPUCountLocal = m_lProcessorsCount
  445. '    End If
  446. '
  447. 'End Function
  448.  
  449.  
  450.  
  451. Public Function GetCPUCount() As Long
  452. Dim res As Long, lResultkey As Long
  453. Dim lReserve As Long, sClass As String, lClass As Long, ft As FILETIME, lName As Long, sName As String
  454. Dim nCnt As Long, lOpenResult
  455. Dim sKey As String
  456.     If m_bLocalServer Then
  457.         res = RegConnectRegistry(mvar_RemoteServer, HKEY_LOCAL_MACHINE, lResultkey)
  458.         If res <> 0 Then
  459.             GetCPUCount = -1
  460.             Exit Function
  461.         End If
  462.     Else
  463.         lResultkey = HKEY_LOCAL_MACHINE
  464.     End If
  465.     sKey = "HARDWARE\DESCRIPTION\System\CentralProcessor" & vbNullString
  466.     res = RegOpenKey(lResultkey, sKey, lOpenResult)
  467.     If res = 0 Then
  468.         sClass = Space(255)
  469.         sName = Space(255)
  470.         lClass = 255
  471.         lName = 255
  472.         nCnt = 0
  473.         Do While 1
  474.             sClass = Space(255)
  475.             sName = Space(255)
  476.             lClass = 255
  477.             lName = 255
  478.             res = RegEnumKeyEx(lOpenResult, nCnt, sName, lName, lReserve, sClass, lClass, ft)
  479.             If res <> 0 Then Exit Do
  480.             nCnt = nCnt + 1
  481.         Loop
  482.         
  483.     End If
  484.     m_lProcessorsCount = nCnt
  485.     ReDim m_aPrevCountersCPU(0 To m_lProcessorsCount - 1) As Currency
  486.     ReDim m_aCountersCPU(0 To m_lProcessorsCount - 1) As Currency
  487.     GetCPUCount = nCnt
  488.     RegCloseKey lOpenResult
  489.     RegCloseKey lResultkey
  490. End Function
  491.  
  492. Public Function GetCPUUsage(Optional ByVal CPU_Index As Long = 1) As Long
  493. Dim cpuIndex As Long
  494.     cpuIndex = CPU_Index - 1
  495.  
  496.         If m_lProcessorsCount < 0 Then CollectCPUData
  497.  
  498.         If (cpuIndex >= m_lProcessorsCount) Or (cpuIndex < 0) Then
  499.             Err.Raise Err_CPUIndexOOB, ClassName & ".GetCPUUsageLocal()", "CPU index out of bounds"
  500.         End If
  501.  
  502.         If PrevSysTime = SysTime Then
  503.             GetCPUUsage = 0
  504.         Else
  505.             GetCPUUsage = CLng(100 * (1 - (m_aCountersCPU(cpuIndex) - m_aPrevCountersCPU(cpuIndex)) / (SysTime - PrevSysTime)))
  506.         End If
  507.  
  508.  
  509. End Function
  510. 'Public Function GetCPUUsageRemote(Optional ByVal CPU_Index As Long = 1) As Long
  511. 'Dim cpuIndex As Long
  512. '    cpuIndex = CPU_Index - 1
  513. '
  514. '        If m_lProcessorsCount < 0 Then CollectCPUData
  515. '
  516. '        If (cpuIndex >= m_lProcessorsCount) Or (cpuIndex < 0) Then
  517. '            Err.Raise Err_CPUIndexOOB, ClassName & ".GetCPUUsageLocal()", "CPU index out of bounds"
  518. '        End If
  519. '
  520. '        If PrevSysTime = SysTime Then
  521. '            GetCPUUsageRemote = 0
  522. '        Else
  523. '            GetCPUUsageRemote = CLng(100 * (1 - (m_aCountersCPU(cpuIndex) - m_aPrevCountersCPU(cpuIndex)) / (SysTime - PrevSysTime)))
  524. '        End If
  525. '
  526. '
  527. 'End Function
  528.  
  529.  
  530.