Page 1 of 1

CPU analysis

Posted: Sat Nov 16, 2024 8:28 am
by Antonio Linares
Thanks to Charly:

Code: Select all | Expand

LOCAL  oLoc :=  CreateObject( "wbemScripting.SwbemLocator" )
    LOCAL  objWMI := oLoc:ConnectServer()
    LOCAL   hAppInfo := {=>}
    LOCAL   oError, oDatos, oJbs 

    TRY
        oJbs := objWMI:ExecQuery("SELECT * FROM Win32_Processor")
        
        FOR EACH oDatos IN oJbs
            hAppInfo['cpu_usage'] := Alltrim(hb_CStr(oDatos:LoadPercentage))
            hAppInfo['cpu_name'] := Alltrim(hb_CStr(oDatos:Name))
            hAppInfo['cpu_cores'] := Alltrim(hb_CStr(oDatos:NumberOfCores))
            hAppInfo['cpu_threads'] := Alltrim(hb_CStr(oDatos:NumberOfLogicalProcessors))
        NEXT
    CATCH oError
        hAppInfo['cpu_usage'] := '0'
        hAppInfo['cpu_name'] := ''
        hAppInfo['cpu_cores'] := '0'
        hAppInfo['cpu_threads'] := '0'
    END