Sign in to follow this  
Followers 0
argumentum

WMI on Open Hardware Monitor beta

4 posts in this topic

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.
2 people like this

Share this post


Link to post
Share on other sites



i have fun ; )

Share this post


Link to post
Share on other sites

#3 ·  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

Share this post


Link to post
Share on other sites

#4 ·  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

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  
Followers 0

  • Similar Content

    • ModemJunki
      By ModemJunki
      Hello,
      In Windows 10 PowerShell, one can do this to change the metric for a NIC in Windows 10:
      Get-NetAdapter | Where-Object -FilterScript {$_.InterfaceAlias -Eq "Ethernet 2"} | Set-NetIPInterface -InterfaceMetric 2 I know I can script the above PowerShell line (and it works!), but I wanted to try something I hadn't done before after looking into jguinch's most excellent Network configuration UDF. I wanted to make use of the SetIPConnectionMetric method in the WMI classes. There is an example VBscript here but this is not for Windows 10. Using AutoIT would also give better control over capturing error return codes than with PowerShell.
      But I cannot get my script to work! The return from SetIPConnectionMetric() is 0, which would indicate success. Yet the change does not happen. I also tried WMI methods using .put_ but this fails.
      Anyone more experienced than I have ideas to make this work?
      #RequireAdmin _SetNicInterfaceMetric2("Ethernet 2", "2") Func _SetNicInterfaceMetric2($NIC_NAME, $METRIC) Local $s_setIndx = 0 $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2") $colNICItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" & $NIC_NAME & "'", "WQL") If IsObj($colNICItems) Then For $objItem In $colNICItems $s_nicIndex = $objItem.Index Next ConsoleWrite("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = '" & $s_nicIndex & "'" & @CRLF) $colNAC = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = '" & $s_nicIndex & "'", "WQL") If IsObj($colNAC) Then For $objNetCard In $colNAC If $METRIC <> $objNetCard.IPConnectionMetric Then ConsoleWrite("Metric was set to " & $objNetCard.IPConnectionMetric & ". Setting to " & $METRIC & "." & @CRLF) $s_isSet = $objNetCard.SetIPConnectionMetric($METRIC) ConsoleWrite("SetIPConnectionMetric Result = " & $s_isSet & @CRLF) Else ConsoleWrite("Metric is already set to " & $METRIC & @CRLF) EndIf Next EndIf EndIf EndFunc ;==>_SetNicInterfaceMetric2  
    • AndyS19
      By AndyS19
      I have code that does a WMI SQL query to find all defined printers, and I want to parse the returned object in several places.  However, after parsing it the first time, all other times fail to find any printer objects.
      Here is my test code:
      test() Func test() Local $oPrinters, $oPrinter, $err, $cnt, $oP, $query $query = "SELECT * FROM Win32_Printer" $oPrinters = doQuery($query) $err = @error LogMsg("+++: $err = " & $err & ", isObj($oPrinters) = " & IsObj($oPrinters)) If ($err == 0) Then LogMsg("FIRST LOOP") ; <=== FIRST LOOP $cnt = 0 $oP = $oPrinters LogMsg("+++: isObj($oP) = " & IsObj($oP)) For $oPrinter In $oP $cnt += 1 LogMsg("+++: isObj($oPrinter): " & IsObj($oPrinter) & ", $oPrinter.Name ==>" & $oPrinter.Name & "<==") Next LogMsg("+++: Found " & $cnt & " printers") LogMsg("SECOND LOOP") ; <== SECOND LOOP $cnt = 0 $oP = $oPrinters LogMsg("+++: isObj($oP) = " & IsObj($oP)) For $oPrinter In $oP $cnt += 1 LogMsg("+++: isObj($oPrinter): " & IsObj($oPrinter) & ", $oPrinter.Name ==>" & $oPrinter.Name & "<==") Next LogMsg("+++: Found " & $cnt & " printers") EndIf EndFunc ;==>test Func doQuery($sQuery, $lnum = @ScriptLineNumber) #forceref $lnum LogMsg("+++:" & $lnum & ": doQuery(" & '"' & $sQuery & '"' & ") entered") Local $oWMIService, $oResults, $errstr Local $wbemFlags = BitOR(0x20, 0x10) ; $wbemFlagReturnImmediately and wbemFlagForwardOnly $oWMIService = ObjGet("winmgmts:\\" & "localhost" & "\root\CIMV2") If (IsObj($oWMIService)) Then $oResults = $oWMIService.ExecQuery($sQuery, "WQL", $wbemFlags) If (IsObj($oResults)) Then LogMsg("+++: doQuery() returns @error = 0, Good: returning the object") Return (SetError(0, 0, $oResults)) ;;; Good: return the object Else $errstr = "" _ & "WMI Query failed." & @CRLF _ & "This is the query:" & @CRLF _ & " " & $sQuery LogMsg("+++: ====>" & $errstr & "<===") LogMsg("+++: doQuery() returns @error = 1") Return (SetError(1, 0, $errstr)) ; Error: Query faled EndIf Else $errstr = "" _ & "WMI Output" & @CRLF _ & "No WMI Objects Found for class: " & @CRLF _ & "Win32_PrinterDriver" & @CRLF _ & "using this query:" & @CRLF _ & " " & $sQuery LogMsg("+++: ====>" & $errstr & "<===") MsgBox(0, "ERROR", $errstr) ; Error: Cannot get $oWMIService object Exit (1) EndIf EndFunc ;==>doQuery Func LogMsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>LogMsg Parsing the returned $oPrinters object shows 5 printers:
      +++:15: FIRST LOOP +++:18: +++: isObj($oP) = 1 +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Microsoft XPS Document Writer<== +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Microsoft Office Document Image Writer<== +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Fax<== +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Canon MG7100 series Printer WS<== +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Canon MG6100 series Printer WS<== +++:24: +++: Found 5 printers Parsing it again, shows no printers:
      +++:26: SECOND LOOP +++:29: +++: isObj($oP) = 1 +++:35: +++: Found 0 printers  
    • jguinch
      By jguinch
      Hello.
      I did create these few functions several months ago. I post here, if it can interest someone.
      These functions based on WMI queries allow you to manage printers : add / delete printer, driver, port, or obtain configuration, set default printer ... I let you discover it with the code.

       
      Here is the list of the available functions :
      _Printmgr_AddLocalPort
      _Printmgr_AddLPRPort
      _PrintMgr_AddPrinter
      _PrintMgr_AddPrinterDriver
      _PrintMgr_AddTCPIPPrinterPort
      _PrintMgr_AddWindowsPrinterConnection
      _PrintMgr_CancelAllJobs
      _Printmgr_EnumPorts
      _PrintMgr_EnumPrinter
      _PrintMgr_EnumPrinterConfiguration
      _PrintMgr_EnumPrinterDriver
      _PrintMgr_EnumPrinterProperties
      _PrintMgr_EnumTCPIPPrinterPort
      _Printmgr_Pause
      _Printmgr_PortExists
      _Printmgr_PrinterExists
      _Printmgr_PrinterSetComment
      _Printmgr_PrinterSetDriver
      _Printmgr_PrinterSetPort
      _Printmgr_PrinterShare
      _Printmgr_PrintTestPage
      _PrintMgr_RemoveLocalPort
      _PrintMgr_RemoveLPRPort
      _PrintMgr_RemovePrinter
      _PrintMgr_RemovePrinterDriver
      _PrintMgr_RemoveTCPIPPrinterPort
      _PrintMgr_RenamePrinter
      _Printmgr_Resume
      _PrintMgr_SetDefaultPrinter
       
      And some examples :
      #Include "PrintMgr.au3" ; Remove a printer called "My old Lexmark printer" : _PrintMgr_RemovePrinter("My old Lexmark printer") ; Remove the driver called "Lexmark T640" : _PrintMgr_RemovePrinterDriver("Lexmark T640") ; Remove the TCP/IP printer port called "TCP/IP" _PrintMgr_RemoveTCPIPPrinterPort("MyOLDPrinterPort") ; Add a driver, called "Samsung ML-451x 501x Series", and driver inf file is ".\Samsung5010\sse2m.inf" _PrintMgr_AddPrinterDriver("Samsung ML-451x 501x Series", "Windows NT x86", @scriptDir & "\Samsung5010", @scriptDir & "\Samsung5010\sse2m.inf") ; Add a TCP/IP printer port, called "MyTCPIPPrinterPort", with IPAddress = 192.168.1.10 and Port = 9100 _PrintMgr_AddTCPIPPrinterPort("MyTCPIPPrinterPort", "192.168.1.10", 9100) ; Add a printer, give it the name "My Printer", use the driver called "Samsung ML-451x 501x Series" and the port called "MyTCPIPPrinterPort" _PrintMgr_AddPrinter("My Printer", "Samsung ML-451x 501x Series", "MyTCPIPPrinterPort") ; Set the printer called "My Printer" as default printer _PrintMgr_SetDefaultPrinter("My Printer") ; Connect to the shared printer "\\192.168.1.1\HPDeskjetColor") _PrintMgr_AddWindowsPrinterConnection("\\192.168.1.1\HPDeskjetColor") ; List all installed printers #Include <Array.au3> $aPrinterList = _PrintMgr_EnumPrinter() _ArrayDisplay($aPrinterList) ; List all printers configuration #Include <Array.au3> $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration() _ArrayDisplay($aPrinterConfig) ; List all installed printer drivers #Include <Array.au3> $aDriverList = _EnumPrinterDriver() _ArrayDisplay($aDriverList) ; Retrieve the printer configuration for the printer called "Lexmark T640" #Include <Array.au3> $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration("Lexmark T640") _ArrayDisplay($aPrinterConfig) ; Add a local printer port (for a file output) _AddLocalPrinterPort("c:\temp\output.pcl") ; Remove the local port _RemoveLocalPrinterPort("c:\temp\output.pcl") Download link :  PrintMgr.au3
    • jguinch
      By jguinch
      Here is an UDF for managing printers.
      Features are :
       - add, remove or rename a printer
       - add or remove a driver
       - add or remove a TCP/IP printer port
       - add or remove a LPR printer port
       - connect to a remote printer
       - enum printers and there configuration and properties
       - pause resume or cancel all jobs of a printer
       - checks if a printer exists
       - print a test page
       - set the default printer
    • ripdad
      By ripdad
      This function (version 1), was developed solely for applications I needed it for.
      It was only tested with Class names that was needed in those scripts.
      And so, I didn't want to release it by itself because I knew it needed some more
      work before I did that.
      Recently, I delved back into it after several years and am now releasing version 2,
      which was mostly rewritten over the past several weeks.
      What does it do? It retrieves the properties and values pertaining to your computer,
      operating system and devices. All you need is a valid Win32 Class Name.
      So, here it is -- let me know if you have any issues!
      Updated to v2.25, January 14, 2017
      Download: _WMI_InstancesOf_v2.25.au3