Jump to content

Recommended Posts

Posted

The Open Hardware Monitor is a free open source software that monitors temperature sensors, fan speeds, voltages, load and clock speeds of a computer.

I found this has a WMI implementation ( http://openhardwaremonitor.org/documentation/ ) and thought it would be nice to post here.

Some code to get started on Hardware

; Generated by AutoIt ScriptOMatic ; Hardware

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$OutputTitle = ""
$Output = ""
$Output = $Output & '<html><head><title>ScriptOMatic HTML Output</title></head><body> <style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Property </th><th> Value </th></tr>'
$OutputTitle &= '<tr bgcolor="yellow"><td>' & "Computer</td><td>&nbsp;" & $strComputer  & "</td></tr>" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\OpenHardwareMonitor")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Hardware", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   Local $Object_Flag = 0
   For $objItem In $colItems
      $Object_Flag = 1
      $Output &= "<tr><td>HardwareType</td><td>&nbsp;" & $objItem.HardwareType & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Identifier</td><td>&nbsp;" & $objItem.Identifier & "</td></tr>" & @CRLF
      $Output &= "<tr><td>InstanceId</td><td>&nbsp;" & $objItem.InstanceId & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Name</td><td>&nbsp;" & $objItem.Name & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Parent</td><td>&nbsp;" & $objItem.Parent & "</td></tr>" & @CRLF
      $Output &= "<tr><td>ProcessId</td><td>&nbsp;" & $objItem.ProcessId & "</td></tr>" & @CRLF
   Next
  If $Object_Flag = 0 Then Msgbox(1,"WMI Output",$OutputTitle)
   FileWrite(@TempDir & "\Hardware.HTML", $Output )
   Run(@Comspec & " /c start " & @TempDir & "\Hardware.HTML" )
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Hardware" )
Endif

 

Some code to get started on Sensor
; Generated by AutoIt ScriptOMatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$OutputTitle = ""
$Output = ""
$Output = $Output & '<html><head><title>ScriptOMatic HTML Output</title></head><body> <style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Property </th><th> Value </th></tr>'
$OutputTitle &= '<tr bgcolor="yellow"><td>' & "Computer</td><td>&nbsp;" & $strComputer  & "</td></tr>" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\OpenHardwareMonitor")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Sensor", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   Local $Object_Flag = 0
   For $objItem In $colItems
      $Object_Flag = 1
      $Output &= "<tr><td>Identifier</td><td>&nbsp;" & $objItem.Identifier & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Index</td><td>&nbsp;" & $objItem.Index & "</td></tr>" & @CRLF
      $Output &= "<tr><td>InstanceId</td><td>&nbsp;" & $objItem.InstanceId & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Max</td><td>&nbsp;" & $objItem.Max & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Min</td><td>&nbsp;" & $objItem.Min & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Name</td><td>&nbsp;" & $objItem.Name & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Parent</td><td>&nbsp;" & $objItem.Parent & "</td></tr>" & @CRLF
      $Output &= "<tr><td>ProcessId</td><td>&nbsp;" & $objItem.ProcessId & "</td></tr>" & @CRLF
      $Output &= "<tr><td>SensorType</td><td>&nbsp;" & $objItem.SensorType & "</td></tr>" & @CRLF
      $Output &= "<tr><td>Value</td><td>&nbsp;" & $objItem.Value & "</td></tr>" & @CRLF
   Next
  If $Object_Flag = 0 Then Msgbox(1,"WMI Output",$OutputTitle)
   FileWrite(@TempDir & "\Sensor.HTML", $Output )
   Run(@Comspec & " /c start " & @TempDir & "\Sensor.HTML" )
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Sensor" )
Endif
 
have fun.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • 1 year later...
Posted (edited)

a lot of fun... thx for that dude !

;Ressource
    ;Smart Method
        ;https://www.autoitscript.com/forum/topic/91067-drive-temperature/?do=findComment&comment=1091961
    ;OpenHardwareMonitor Method
        ;https://www.autoitscript.com/forum/topic/166268-wmi-on-open-hardware-monitor-beta/#comment-1214360

;======================================================================================================

;Need Run OpenHardwareMonitor
Msgbox(0,"CPU",GetTemp("cpu"))
Msgbox(0,"GPU",GetTemp("gpu"))
Msgbox(0,"Motherboard",GetTemp("lpc"))

;Don't Need Run OpenHardwareMonitor
Msgbox(0,"HDD",GetTemp("hdd"))

;======================================================================================================

;GetTemp($target = "cpu"/"gpu"/"lpc"/"hdd", $strComputer = ".")
Func GetTemp($target, $strComputer = ".")

    If $target = "hdd" Then

        ;Use Smart Method
        Return GetSmartTemp($strComputer)

    Else

        ;Use OpenHardwareMonitor Method

        $wbemFlagReturnImmediately = 0x10
        $wbemFlagForwardOnly = 0x20
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\OpenHardwareMonitor")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Sensor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
        $value = ""

        If IsObj($colItems) then
            For $objItem In $colItems
                If $objItem.SensorType = "Temperature" Then
                    If StringInStr($objItem.Identifier, $target & "/") > 0 Then
                        If $value = "" Then
                            $value = Round($objItem.Value)
                        Else
                            $Comparevalue = Round($objItem.Value)
                            If $Comparevalue > $value Then $value = $Comparevalue
                        EndIf
                    EndIf
                EndIf
            Next
            Return $value
        Else
            Return $value
        Endif

    EndIf

EndFunc ;GetTemp()

Func GetSmartTemp($strComputer = ".")

    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\WMI")
    Local $s, $i, $strVendorSpecific, $colTemp
    $colTemp = $objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_ATAPISmartData")

    If IsObj($colTemp) then
        For $objItem In $colTemp
            $strVendorSpecific = $objItem.VendorSpecific
            For $i = 2 To UBound($strVendorSpecific) - 1 Step 12
                If $strVendorSpecific[$i] = 0xC2 Then; find Vendor Parameter #194 - Temperatur
                    $s &= " " & $strVendorSpecific[$i + 5]; Raw/Value celsuis
                    ContinueLoop 2
                EndIf
            Next
            For $i = 2 To UBound($strVendorSpecific) - 1 Step 12
                If $strVendorSpecific[$i] = 0xBE Then; find Vendor Parameter #190 - Airflow Temperatur (if no tempetature is found)
                    $s &= " " & $strVendorSpecific[$i + 5]; Raw/Value celsuis
                    ContinueLoop 2
                EndIf
            Next
        Next
    Else
        $s = ""
    EndIf
    Return $s

EndFunc ;==> GetSmartTemp()

 

Edited by Synapsee
minor code edit
  • 1 year later...
Posted (edited)

All 3 scripts worked OK for me, now all of a sudden they do not work.

I'm on Windows 10, only one account, Local Account, Administrator.

Running OpenHardwareMonitor.exe and compiled script .EXE as administrator, OpenHardwareMonitor.exe is running and working perfectly.

The first two scripts just create some empty HTML, only  Property | Value table header, no data.

Third script displays only HDD temperature, that is working because it is not reported by "\root\OpenHardwareMonitor", but by "\root\WMI".

 

Update: I installed OpenHardwareMonitor 0.8.0.3 Alpha and it works.

Before I had 0.8.x.x (I can't remember exactly), that was also supposed to work, too.

Edited by queensoft
  • argumentum changed the title to WMI on Libre/Open Hardware Monitor
  • Solution
Posted (edited)

Open Hardware Monitor was abandoned :( 

Libre Hardware Monitor is here :) 

; Generated by https://www.autoitscript.com/forum/files/file/338-scriptomatic-warraysupport ; Hardware
#include <Array.au3>

Opt("MustDeclareVars",1)
Opt("TrayIconDebug",1)
Opt("TrayAutoPause",0)
Global $_nice_COMerrorArray, $_nice_COMerrorObj
_nice_COMerrorHandler(1) ; COM error handler.

ToolTip("mouse over the trayicon for debug info.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",1,4)

Local $a = _WMI_Hardware()
If @error Then
    Switch @error
        Case 1
            MsgBox(262144, "WMI ScriptOMatic error", "No WMI Objects Found for class: ""Hardware""" )
        Case 2
            MsgBox(262144, "WMI ScriptOMatic error", "ObjGet failed")
        Case 3
            MsgBox(262144, "WMI ScriptOMatic error", "ObjCreate failed")
        Case 4
            MsgBox(262144, "WMI ScriptOMatic error", "ConnectServer failed")
        Case Else
            MsgBox(262144, "WMI ScriptOMatic error", "unknown error")
    EndSwitch
Else
    Switch @extended
        Case 0
            ToolTip("Done.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",1,4)
        Case 1
            ToolTip("Nothing, you've got nothing."&@CR&@CR&"Adjust the query", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",2,4)
        Case 2
            ToolTip("More than you can chew."&@CR&@CR&"Adjust the ""$iLimit"" or the query", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",2,4)
    EndSwitch
    If $_nice_COMerrorArray[0][0] Then _nice_COMerrorHandler(2)
    _Array_Rotate2D( $a )
    _ArrayDisplay( $a ,"ScriptOMatic - ""Hardware""")
EndIf


Func _WMI_Hardware( $iLimit = 1000 , $sComputer = "." , $sUser = "" , $sPassword = "" )

    ; Generated by AutoIt ScriptOMatic ; https://www.autoitscript.com/forum/topic/166268-wmi-on-libreopen-hardware-monitor/#findComment-1547553

    ; Description:


    ; Class Methods:
    ;
    ; ( this Class did not list methods )


    Local $wbemFlagReturnImmediately = 0x10
    Local $wbemFlagForwardOnly = 0x20
    Local $colItems = ""
    Local $sReturn=""
    Local $iExt = 0
    If 1 > Int( $iLimit ) Then $iLimit = 1
    Local $aReturn[1000][ Int( $iLimit ) + 1]
    $aReturn[0][0] = 0
    $aReturn[0][1] = 0
    Local $aErr[1][2] = [[0, 0]]

    If $sComputer & $sUser & $sPassword = "." Then
        ToolTip("...ObjGet", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",1,4)
        Local $oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\root\LibreHardwareMonitor")
        If Not IsObj($oWMIService) Then Return SetError(2, 99, $aErr)
    Else
        ToolTip("...ObjCreate", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",1,4)
        Local $wmiLocator = ObjCreate("WbemScripting.SWbemLocator")
        If Not IsObj($wmiLocator) Then Return SetError(3, 99, $aErr)
        ToolTip("...ConnectServer", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",1,4)
        Local $oWMIService = $wmiLocator.ConnectServer($sComputer, "\root\LibreHardwareMonitor", $sUser, $sPassword)
        If Not IsObj($oWMIService) Then Return SetError(4, 99, $aErr)
    EndIf

    ToolTip("...ExecQuery", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",1,4)
    Local $colItems = $oWMIService.ExecQuery("SELECT * FROM Hardware", _
                         "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    ToolTip("...ExecQuery executed."& @CR &"...waiting for data.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",1,4)
    If IsObj($colItems) Then

        ; Class Properties: Names:
        ;

        $aReturn[ 1 ][ 0 ] = "HardwareType"
        $aReturn[ 2 ][ 0 ] = "Identifier"
        $aReturn[ 3 ][ 0 ] = "InstanceId"
        $aReturn[ 4 ][ 0 ] = "Name"
        $aReturn[ 5 ][ 0 ] = "Parent"
        $aReturn[ 6 ][ 0 ] = "ProcessId"
        $aReturn[0][0] = 6
        For $objItem In $colItems
            $aReturn[0][1] = $aReturn[0][1] + 1
            If Not Mod( $aReturn[0][1] , 100 ) Then ToolTip("...adding "& $aReturn[0][1] &" of "&$iLimit &" ??", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Hardware",1,4)
            If $aReturn[0][1] > $iLimit Then
                $iExt = 2
                ExitLoop
            EndIf

            ; Class Properties: Values:
            ;

            $aReturn[ 1 ][ $aReturn[0][1] ] = $objItem.HardwareType
            $aReturn[ 2 ][ $aReturn[0][1] ] = $objItem.Identifier
            $aReturn[ 3 ][ $aReturn[0][1] ] = $objItem.InstanceId
            $aReturn[ 4 ][ $aReturn[0][1] ] = $objItem.Name
            $aReturn[ 5 ][ $aReturn[0][1] ] = $objItem.Parent
            $aReturn[ 6 ][ $aReturn[0][1] ] = $objItem.ProcessId
        Next
        If $aReturn[0][1] = 0  Then $iExt = 1
        ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1] + 1]
        Return SetError( 0 , $iExt , $aReturn )
    Else
        Return SetError(1 ,99 ,$aErr)
    EndIf
EndFunc


Func _Array_Rotate2D(ByRef $a)
    Local $u1 = UBound($a, 1) - 1
    If @error Then Return SetError(1)
    Local $u2 = UBound($a, 2) - 1
    If @error Then
        Local $n, $m, $u2 = 1
        Local $b[$u2][$u1 + 1]
        For $n = 0 To $u1
            For $m = 0 To 0
                $b[$m][$n] = $a[$n]
            Next
        Next
    Else
        Local $n, $m
        Local $b[$u2 + 1][$u1 + 1]
        For $n = 0 To $u1
            For $m = 0 To $u2
                $b[$m][$n] = $a[$n][$m]
            Next
        Next
    EndIf
    $a = $b
EndFunc   ;==>_Array_Rotate2D
#Region    # ValueToDescription Functions #



#EndRegion # ValueToDescription Functions #

Func _nice_COMerrorHandler($i = 0)
    If $i == 1 Then
        Dim $_nice_COMerrorArray[301][9]
        $_nice_COMerrorArray[0][0] = 0
        $_nice_COMerrorObj = ObjEvent("AutoIt.Error", "_nice_COMerrorHandler")
        Return
    EndIf
    If $i == 2 Then
        If Not @Compiled Then
            Local $n = 0, $c = 0, $s = FileRead(@ScriptFullPath)
            Local $a = StringSplit($s, @CRLF, 1)
            For $n = 1 To $_nice_COMerrorArray[0][0]
                If Int($_nice_COMerrorArray[$n][7]) > $a[0] Then ContinueLoop
                $_nice_COMerrorArray[$n][8] = StringStripWS($a[Int($_nice_COMerrorArray[$n][7])], 3)
            Next
            If StringInStr($s, "; only for the ANSI compiled version" & @CRLF) Then
                For $n = 1 To $a[0]
                    If StringInStr($a[$n], "; only for the ANSI compiled version") Then $c += 1
                    If $n > 50 Then ExitLoop
                Next
                For $n = 1 To $_nice_COMerrorArray[0][0]
                    $_nice_COMerrorArray[$n][7] = $_nice_COMerrorArray[$n][7] - $c
                Next
            EndIf
        EndIf
        $_nice_COMerrorArray[1][0] = ""
        ReDim $_nice_COMerrorArray[$_nice_COMerrorArray[0][0] + 1][9]
        _ArrayDisplay($_nice_COMerrorArray, "ScriptOMatic - COM Errors intercepted ( the script will continue after this screen )")
        Return
    EndIf
    If $_nice_COMerrorArray[0][0] = 300 Then
        $_nice_COMerrorArray[0][8] = "ScriptLine: only first 300 errors shown !!!"
        Return
    EndIf
    If StringInStr($_nice_COMerrorArray[1][0], "|" & $_nice_COMerrorObj.scriptline & "|") Then Return
    $i = $_nice_COMerrorArray[0][0] + 1
    $_nice_COMerrorArray[0][0] = $i
    $_nice_COMerrorArray[$i][1] = "0x" & Hex($_nice_COMerrorObj, 8)
    $_nice_COMerrorArray[$i][2] = $_nice_COMerrorObj.windescription
    $_nice_COMerrorArray[$i][3] = $_nice_COMerrorObj.source
    $_nice_COMerrorArray[$i][4] = $_nice_COMerrorObj.helpfile
    $_nice_COMerrorArray[$i][5] = $_nice_COMerrorObj.helpcontext
    $_nice_COMerrorArray[$i][6] = $_nice_COMerrorObj.lastdllerror
    $_nice_COMerrorArray[$i][7] = $_nice_COMerrorObj.scriptline
    $_nice_COMerrorArray[1][0] = $_nice_COMerrorArray[1][0] & "|" & $_nice_COMerrorObj.scriptline & "|"
    If $i == 1 Then
        $_nice_COMerrorArray[0][1] = "ErrorNumber:"
        $_nice_COMerrorArray[0][2] = "WinDescription:"
        $_nice_COMerrorArray[0][3] = "Source:"
        $_nice_COMerrorArray[0][4] = "HelpFile:"
        $_nice_COMerrorArray[0][5] = "HelpContext:"
        $_nice_COMerrorArray[0][6] = "LastDLLerror:"
        $_nice_COMerrorArray[0][7] = "ScriptLineNumber:"
        $_nice_COMerrorArray[0][8] = "ScriptLine:"
    EndIf
EndFunc   ;==>_nice_COMerrorHandler


#comments-start

List of all the Properties and Methods for \root\LibreHardwareMonitor:Hardware


Hardware Class Qualifiers
-------------------------

1. dynamic = True
2. provider = LibreHardwareMonitor_SN__Version_0.9.4.0


Hardware Class Properties and Property Qualifiers
-------------------------------------------------

1. HardwareType
1.1. CIMTYPE = string

2. Identifier
2.1. CIMTYPE = string

3. InstanceId
3.1. CIMTYPE = string
3.2. key = True

4. Name
4.1. CIMTYPE = string

5. Parent
5.1. CIMTYPE = string

6. ProcessId
6.1. CIMTYPE = string
6.2. key = True


Hardware Class Methods and Method Qualifiers
--------------------------------------------

#comments-end

 

; Generated by https://www.autoitscript.com/forum/files/file/338-scriptomatic-warraysupport ; Sensor
#include <Array.au3>

Opt("MustDeclareVars",1)
Opt("TrayIconDebug",1)
Opt("TrayAutoPause",0)
Global $_nice_COMerrorArray, $_nice_COMerrorObj
_nice_COMerrorHandler(1) ; COM error handler.

ToolTip("mouse over the trayicon for debug info.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",1,4)

Local $a = _WMI_Sensor()
If @error Then
    Switch @error
        Case 1
            MsgBox(262144, "WMI ScriptOMatic error", "No WMI Objects Found for class: ""Sensor""" )
        Case 2
            MsgBox(262144, "WMI ScriptOMatic error", "ObjGet failed")
        Case 3
            MsgBox(262144, "WMI ScriptOMatic error", "ObjCreate failed")
        Case 4
            MsgBox(262144, "WMI ScriptOMatic error", "ConnectServer failed")
        Case Else
            MsgBox(262144, "WMI ScriptOMatic error", "unknown error")
    EndSwitch
Else
    Switch @extended
        Case 0
            ToolTip("Done.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",1,4)
        Case 1
            ToolTip("Nothing, you've got nothing."&@CR&@CR&"Adjust the query", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",2,4)
        Case 2
            ToolTip("More than you can chew."&@CR&@CR&"Adjust the ""$iLimit"" or the query", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",2,4)
    EndSwitch
    If $_nice_COMerrorArray[0][0] Then _nice_COMerrorHandler(2)
    _Array_Rotate2D( $a )
    _ArrayDisplay( $a ,"ScriptOMatic - ""Sensor""")
EndIf


Func _WMI_Sensor( $iLimit = 1000 , $sComputer = "." , $sUser = "" , $sPassword = "" )

    ; Generated by AutoIt ScriptOMatic ; https://www.autoitscript.com/forum/topic/166268-wmi-on-libreopen-hardware-monitor/#findComment-1547553

    ; Description: 


    ; Class Methods:
    ;
    ; ( this Class did not list methods )


    Local $wbemFlagReturnImmediately = 0x10
    Local $wbemFlagForwardOnly = 0x20
    Local $colItems = ""
    Local $sReturn=""
    Local $iExt = 0
    If 1 > Int( $iLimit ) Then $iLimit = 1
    Local $aReturn[1000][ Int( $iLimit ) + 1]
    $aReturn[0][0] = 0
    $aReturn[0][1] = 0
    Local $aErr[1][2] = [[0, 0]]

    If $sComputer & $sUser & $sPassword = "." Then
        ToolTip("...ObjGet", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",1,4)
        Local $oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\root\LibreHardwareMonitor")
        If Not IsObj($oWMIService) Then Return SetError(2, 99, $aErr)
    Else
        ToolTip("...ObjCreate", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",1,4)
        Local $wmiLocator = ObjCreate("WbemScripting.SWbemLocator")
        If Not IsObj($wmiLocator) Then Return SetError(3, 99, $aErr)
        ToolTip("...ConnectServer", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",1,4)
        Local $oWMIService = $wmiLocator.ConnectServer($sComputer, "\root\LibreHardwareMonitor", $sUser, $sPassword)
        If Not IsObj($oWMIService) Then Return SetError(4, 99, $aErr)
    EndIf

    ToolTip("...ExecQuery", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",1,4)
    Local $colItems = $oWMIService.ExecQuery("SELECT * FROM Sensor", _
                         "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    ToolTip("...ExecQuery executed."& @CR &"...waiting for data.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",1,4)
    If IsObj($colItems) Then

        ; Class Properties: Names:
        ;

        $aReturn[  1 ][ 0 ] = "Identifier"
        $aReturn[  2 ][ 0 ] = "Index"
        $aReturn[  3 ][ 0 ] = "InstanceId"
        $aReturn[  4 ][ 0 ] = "Max"
        $aReturn[  5 ][ 0 ] = "Min"
        $aReturn[  6 ][ 0 ] = "Name"
        $aReturn[  7 ][ 0 ] = "Parent"
        $aReturn[  8 ][ 0 ] = "ProcessId"
        $aReturn[  9 ][ 0 ] = "SensorType"
        $aReturn[ 10 ][ 0 ] = "Value"
        $aReturn[0][0] = 10
        For $objItem In $colItems
            $aReturn[0][1] = $aReturn[0][1] + 1
            If Not Mod( $aReturn[0][1] , 100 ) Then ToolTip("...adding "& $aReturn[0][1] &" of "&$iLimit &" ??", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Sensor",1,4)
            If $aReturn[0][1] > $iLimit Then
                $iExt = 2
                ExitLoop
            EndIf

            ; Class Properties: Values:
            ;

            $aReturn[  1 ][ $aReturn[0][1] ] = $objItem.Identifier
            $aReturn[  2 ][ $aReturn[0][1] ] = $objItem.Index
            $aReturn[  3 ][ $aReturn[0][1] ] = $objItem.InstanceId
            $aReturn[  4 ][ $aReturn[0][1] ] = $objItem.Max
            $aReturn[  5 ][ $aReturn[0][1] ] = $objItem.Min
            $aReturn[  6 ][ $aReturn[0][1] ] = $objItem.Name
            $aReturn[  7 ][ $aReturn[0][1] ] = $objItem.Parent
            $aReturn[  8 ][ $aReturn[0][1] ] = $objItem.ProcessId
            $aReturn[  9 ][ $aReturn[0][1] ] = $objItem.SensorType
            $aReturn[ 10 ][ $aReturn[0][1] ] = $objItem.Value
        Next
        If $aReturn[0][1] = 0  Then $iExt = 1
        ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1] + 1]
        Return SetError( 0 , $iExt , $aReturn )
    Else
        Return SetError(1 ,99 ,$aErr)
    EndIf
EndFunc


Func _Array_Rotate2D(ByRef $a)
    Local $u1 = UBound($a, 1) - 1
    If @error Then Return SetError(1)
    Local $u2 = UBound($a, 2) - 1
    If @error Then
        Local $n, $m, $u2 = 1
        Local $b[$u2][$u1 + 1]
        For $n = 0 To $u1
            For $m = 0 To 0
                $b[$m][$n] = $a[$n]
            Next
        Next
    Else
        Local $n, $m
        Local $b[$u2 + 1][$u1 + 1]
        For $n = 0 To $u1
            For $m = 0 To $u2
                $b[$m][$n] = $a[$n][$m]
            Next
        Next
    EndIf
    $a = $b
EndFunc   ;==>_Array_Rotate2D
#Region    # ValueToDescription Functions #



#EndRegion # ValueToDescription Functions #

Func _nice_COMerrorHandler($i = 0)
    If $i == 1 Then
        Dim $_nice_COMerrorArray[301][9]
        $_nice_COMerrorArray[0][0] = 0
        $_nice_COMerrorObj = ObjEvent("AutoIt.Error", "_nice_COMerrorHandler")
        Return
    EndIf
    If $i == 2 Then
        If Not @Compiled Then
            Local $n = 0, $c = 0, $s = FileRead(@ScriptFullPath)
            Local $a = StringSplit($s, @CRLF, 1)
            For $n = 1 To $_nice_COMerrorArray[0][0]
                If Int($_nice_COMerrorArray[$n][7]) > $a[0] Then ContinueLoop
                $_nice_COMerrorArray[$n][8] = StringStripWS($a[Int($_nice_COMerrorArray[$n][7])], 3)
            Next
            If StringInStr($s, "; only for the ANSI compiled version" & @CRLF) Then
                For $n = 1 To $a[0]
                    If StringInStr($a[$n], "; only for the ANSI compiled version") Then $c += 1
                    If $n > 50 Then ExitLoop
                Next
                For $n = 1 To $_nice_COMerrorArray[0][0]
                    $_nice_COMerrorArray[$n][7] = $_nice_COMerrorArray[$n][7] - $c
                Next
            EndIf
        EndIf
        $_nice_COMerrorArray[1][0] = ""
        ReDim $_nice_COMerrorArray[$_nice_COMerrorArray[0][0] + 1][9]
        _ArrayDisplay($_nice_COMerrorArray, "ScriptOMatic - COM Errors intercepted ( the script will continue after this screen )")
        Return
    EndIf
    If $_nice_COMerrorArray[0][0] = 300 Then
        $_nice_COMerrorArray[0][8] = "ScriptLine: only first 300 errors shown !!!"
        Return
    EndIf
    If StringInStr($_nice_COMerrorArray[1][0], "|" & $_nice_COMerrorObj.scriptline & "|") Then Return
    $i = $_nice_COMerrorArray[0][0] + 1
    $_nice_COMerrorArray[0][0] = $i
    $_nice_COMerrorArray[$i][1] = "0x" & Hex($_nice_COMerrorObj, 8)
    $_nice_COMerrorArray[$i][2] = $_nice_COMerrorObj.windescription
    $_nice_COMerrorArray[$i][3] = $_nice_COMerrorObj.source
    $_nice_COMerrorArray[$i][4] = $_nice_COMerrorObj.helpfile
    $_nice_COMerrorArray[$i][5] = $_nice_COMerrorObj.helpcontext
    $_nice_COMerrorArray[$i][6] = $_nice_COMerrorObj.lastdllerror
    $_nice_COMerrorArray[$i][7] = $_nice_COMerrorObj.scriptline
    $_nice_COMerrorArray[1][0] = $_nice_COMerrorArray[1][0] & "|" & $_nice_COMerrorObj.scriptline & "|"
    If $i == 1 Then
        $_nice_COMerrorArray[0][1] = "ErrorNumber:"
        $_nice_COMerrorArray[0][2] = "WinDescription:"
        $_nice_COMerrorArray[0][3] = "Source:"
        $_nice_COMerrorArray[0][4] = "HelpFile:"
        $_nice_COMerrorArray[0][5] = "HelpContext:"
        $_nice_COMerrorArray[0][6] = "LastDLLerror:"
        $_nice_COMerrorArray[0][7] = "ScriptLineNumber:"
        $_nice_COMerrorArray[0][8] = "ScriptLine:"
    EndIf
EndFunc   ;==>_nice_COMerrorHandler


#comments-start

List of all the Properties and Methods for \root\LibreHardwareMonitor:Sensor


Sensor Class Qualifiers
-----------------------

1. dynamic = True
2. provider = LibreHardwareMonitor_SN__Version_0.9.4.0


Sensor Class Properties and Property Qualifiers
-----------------------------------------------

1. Identifier
1.1. CIMTYPE = string

2. Index
2.1. CIMTYPE = sint32

3. InstanceId
3.1. CIMTYPE = string
3.2. key = True

4. Max
4.1. CIMTYPE = real32

5. Min
5.1. CIMTYPE = real32

6. Name
6.1. CIMTYPE = string

7. Parent
7.1. CIMTYPE = string

8. ProcessId
8.1. CIMTYPE = string
8.2. key = True

9. SensorType
9.1. CIMTYPE = string

10. Value
10.1. CIMTYPE = real32


Sensor Class Methods and Method Qualifiers
------------------------------------------

#comments-end

 

If you enable the web interface ( Options > Remote web server ) then you can get the data anywhere in your network ( or just your PC  ):

#include <JSON.au3> ; https://github.com/Sylvan86/autoit-json-udf
#include <Array.au3>

; extract array of devices from the json structure
Global $aDevices = _JSON_LHM_ExtractDevices(_JSON_Parse(BinaryToString(InetRead("http://192.168.0.127:8085/data.json")))) ; use your IP and PORT

; display the result
_ArrayDisplay($aDevices, "Devices", "", 64, "|", "Index|JSON-Path|ID|Text|Min|Value|Max|SensorID|Type|ImageURL")


Func _JSON_LHM_ExtractDevices($mDevice, $bMaster = True, $sIndex = 0)
    Local Static $aDevices[0][0], $iElements ; https://www.autoitscript.com/forum/topic/213328-walking-a-json-and-failing/#findComment-1547542
    Local Enum $eIdx, $ePath, $eID, $eText, $eMin, $eValue, $eMax, $eSensorID, $eType, $eImg

    ; check Input validity
    If Not IsMap($mDevice) Then Return SetError(1, 0, Null)

    ; first recursion level has to initialize things
    If $bMaster Then
        ReDim $aDevices[8][$eImg + 1]
        $iElements = 0
    EndIf

    ; add current device to result array
    If UBound($aDevices) <= $iElements Then ReDim $aDevices[UBound($aDevices) * 2][$eImg + 1] ; resize array if necessary
    $aDevices[$iElements][$eIdx] = $sIndex
    $aDevices[$iElements][$ePath] = StringReplace(StringRegExpReplace(StringTrimLeft($sIndex, 2), "(\d+)", 'Children[$1]'), ',', '.')
    $aDevices[$iElements][$eID] = $mDevice["id"]
    $aDevices[$iElements][$eText] = $mDevice["Text"]
    $aDevices[$iElements][$eMin] = $mDevice["Min"]
    $aDevices[$iElements][$eValue] = $mDevice["Value"]
    $aDevices[$iElements][$eMax] = $mDevice["Max"]
    $aDevices[$iElements][$eSensorID] = $mDevice["SensorId"]
    $aDevices[$iElements][$eType] = $mDevice["Type"]
    $aDevices[$iElements][$eImg] = $mDevice["ImageURL"]
    $iElements += 1

    ; process the childrens
    Local $aChildren = $mDevice["Children"]
    If IsArray($aChildren) And UBound($aChildren, 1) > 0 And UBound($aChildren, 0) = 1 Then
        For $i = 0 To UBound($aChildren) - 1
            _JSON_LHM_ExtractDevices($aChildren[$i], False, $sIndex & "," & $i)
        Next
    EndIf

    If $bMaster Then
        ReDim $aDevices[$iElements][$eImg + 1]
        Return $aDevices
    EndIf
EndFunc   ;==>_JSON_LHM_ExtractDevices

To make it bind to all networks or local or any IPv4 and port you'll need to edit this by hand ( as it only shows NIC IPs )

<add key="listenerIp" value="0.0.0.0" />
<add key="listenerPort" value="8085" />

in LibreHardwareMonitor.config
The file is created after you close LibreHardwareMonitor.exe, because it only updates/saves the file after exit.

If for any reason you don't want to see the icon, hide the GUI

#RequireAdmin
Local $sWinTitleEx = "[TITLE:Libre Hardware Monitor;REGEXPCLASS:(?i)(WindowsForms*);]"
Local $hWin = WinGetHandle($sWinTitleEx)
If $hWin Then WinSetState($hWin, "", @SW_HIDE) ; or @SW_SHOW
; If $hWin Then WinClose($hWin) ; when you're done


Needless to say that unless LibreHardwareMonitor.exe is running, no Web or WMI will return a value. 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...