Jump to content

WMI on Open Hardware Monitor beta


argumentum
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • 1 year later...

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
Link to comment
Share on other sites

  • 1 year later...

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
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...