Jump to content
Sign in to follow this  
argumentum

WMI on Open Hardware Monitor beta

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi AutoIt Programmers!

      I've seen a code that gives Name of Group by writing it's group's SID, but this one response very slower than Windows Command-Line WMIC
       
      Func _GetLocalGroupName($sSID = 'S-1-5-18') $objWMIService = ObjGet ("winmgmts:\\" & @ComputerName & "\root\cimv2") $colItems = $objWMIService.ExecQuery('SELECT Name FROM Win32_Group where SID="' & $sSID & '"') For $GroupNames in $colItems MsgBox (0,"",$GroupNames.Name) ExitLoop Next EndFunc I don't want call and use any third-party programs even CMD, i just want use from Windows API, netapi32.dll or AutoIt Functions (Standalone).
      Do you have any idea to improve speed/performance of this code? I'll happy of your comments
       
       
       
      ====================== SOLOUTION by @Subz ======================
       
    • By jresine
      Hello, is it possible to know via a script or command, to have the percentage of disk usage of a process? thank you in advance.
      ps: see image

    • By Dwalfware
      HI
      Another head scratched
      Anyone solve how to get the IPV6 from WMI?
      I followed the usual SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID='" & GUICtrlRead($cboAdapters) & "'
      get the index 
      port it to 
      Local $query = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 )
      All i can see is IPv4 addresses
      My question is is there another place the IPv6 information is hiding? I configured my LAN with IPV6 and my wireless with IPv4 so I can see what shows.
      Thanks in Advance.
      PS. I did try google
       
    • By Dwalfware
      Hi Folks
      Can not get my head around this one.
      This function gets the DNS object s
      If you have two DNS entries fine. but if you have only one! Trouble
      $objItem.DNSServerSearchOrder[0] = Primary DNS
      $objItem.DNSServerSearchOrder[1] = Secondry DNS not always there. I need a way to return 0 if not there or the IP if its there.
      Or is there a way to tell how many objects there are in the "[?]"
      I'm terrible at WMI errors, thanks for help in advance.
      Func _GETcurrentNICinfo2() $oErrors = ObjEvent("AutoIt.Error", "Error_Handle") Local $DnsSecondry Local $objWMIService = ObjGet( "winmgmts:\\" & @ComputerName & "\root\CIMV2" ) Local $query = $objWMIService.ExecQuery("SELECT DNSServerSearchOrder FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 ) If @error Then Return 0 If NOT IsObj($query) Then Return 0 Else For $objItem In $query Return $objItem.DNSServerSearchOrder[1] next Endif EndFunc  
    • By amin84
      Hello,
      I'm having trouble getting information from Win32_Processor:
      https://docs.microsoft.com/en-us/windows/desktop/CIMWin32Prov/win32-processor
      How does this WMI Query work? Let's say I need to query VMMonitorModeExtensions, Level, ProcessorId, and ProcessorType.
      How would this work?
      Thanks.
×
×
  • Create New...