Smart_Analysis.au3

Last modified:   Sunday, 26 October 2008

#cs
   This AutoIt script file was generated by Project Express 4.0.6.9 Mar 09 / 2008
   AutoIt Compiler Version: 		3.2.11.1
   Language:		English (US)
   Platform: 		All
   Author: 		George Gedye
   Company: 		GEOSoft Software
   E-Mail:		geog AT mvps DOT org
   ;
   PX Project Name: 		Smart Analysis
   Project Description: 		S.M.A.R.T.  Drive Analysis GUI
   Remarks								WMI analysis code by ptrex and ChrisL
#ce
Global $yPos = 65, $strVendorSpecific2

Opt ("GUICoordMode","2")
Const $wbemFlagReturnImmediately = 0x10
Const $wbemFlagForwardOnly = 0x20
Dim $strComputer = "." 
Dim $objWMIService, $oMyError, $oDict, $oDictType
Dim $colItems, $strReserved, $strVendorSpecific, $strVendorSpecific4, $Output
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
Global $fWarn = False, $iTempScale = -1, $iTempRef = 0
$Drives = DriveGetDrive("Fixed")
$Comb_Data = StringUpper(_ArrayToString($Drives,"|", 1))
Local $Col_w1 = 190, $Col_w2 = 70, $Col_w3 = 70, $Col_w4 = 60, $Col_w5 = 50, $Col_w6 = 40,$Col_w7 = 60
$Frm_Main = GUICreate("S.M.A.R.T. Drive Analysis", 580,550)
GUISetFont(10)
$Menu_Opts = GUICtrlCreateMenu("&Options")
$Menu_Temp = GUICtrlCreateMenu("&Temperature", $Menu_Opts)
$Menu_TempC = GUICtrlCreateMenuItem("&Celcius", $Menu_Temp, -1, 1)
GUICtrlSetState(-1, 65)
$Menu_TempF = GUICtrlCreateMenuItem("&Farenheit", $Menu_Temp, -1, 1)
$Lbl_Dsel = GUICtrlCreateLabel("Select Drive", 10,10, 80, 20)
$Combo_Dsel = GUICtrlCreateCombo("", 0,-1, 60, 30)
$Lbl_Proc = GUICtrlCreateLabel("", 20, -1, 280, 20)
GUICtrlSetData($Combo_Dsel, $Comb_Data, StringUpper($Drives[1]))
GuiSetCoord(10, 45)
$Lbl_Attrib = GUICtrlCreateLabel("Attribute", -1,-1, $Col_w1,30, 1)
$Lbl_Type = GUICtrlCreateLabel("Type", 3, -1,$Col_w2,-1,1)
$Lbl_Flag = GUICtrlCreateLabel("Flag", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh = GUICtrlCreateLabel("Threshold", 3, -1, $Col_w4, -1,1)
$Lbl_Val = GUICtrlCreateLabel("Value", 3, -1, $Col_w5, -1,1)
$Lbl_Worst = GUICtrlCreateLabel("Worst", 3, -1, $Col_w6, -1,1)
$Lbl_Stat = GUICtrlCreateLabel("Status", 3, -1, $Col_w7, -1,1)

$Start = GUICtrlCreateDummy()
GuiSetCoord(10,65)
;GuiSetCoord(10,$yPos)
$Lbl_Attrib1 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type1 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag1 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh1 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val1 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst1 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat1 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GUISetCoord(10,85)
;GUISetCoord(10,$yPos)
$Lbl_Attrib2 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type2 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag2 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh2 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val2 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst2 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat2 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10,105)
$Lbl_Attrib3 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type3 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag3 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh3 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val3 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst3 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat3 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 125)
$Lbl_Attrib4 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type4 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag4 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh4 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val4 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst4 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat4 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 145)
$Lbl_Attrib5 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type5 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag5 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh5 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val5 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst5 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat5 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 165)
$Lbl_Attrib6 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type6 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag6 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh6 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val6 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst6 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat6 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 185)
$Lbl_Attrib7 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type7 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag7 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh7 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val7 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst7 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat7 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 205)
$Lbl_Attrib8 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type8 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag8 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh8 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val8 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst8 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat8 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 225)
$Lbl_Attrib9 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type9 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag9 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh9 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val9 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst9 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat9 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 245)
$Lbl_Attrib10 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type10 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag10 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh10 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val10 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst10 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat10 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 265)
$Lbl_Attrib11 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20) ;; Temperature??
$Lbl_Type11 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag11 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh11 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val11 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst11 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat11 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 285)
$Lbl_Attrib12 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type12 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag12 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh12 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val12 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst12 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat12 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 305)
$Lbl_Attrib13 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type13 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag13 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh13 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val13 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst13 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat13 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 325)
$Lbl_Attrib14 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type14 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag14 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh14 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val14 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst14 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat14 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 345)
$Lbl_Attrib15 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type15 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag15 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh15 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val15 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst15 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat15 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GUISetCoord(10, 365)
$Lbl_Attrib16 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type16 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag16 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh16 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val16 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst16 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat16 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 385)
$Lbl_Attrib17 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type17 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag17 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh17 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val17 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst17 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat17 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 405)
$Lbl_Attrib18 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type18 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag18 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh18 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val18 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst18 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat18 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 425)
$Lbl_Attrib19 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type19 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag19 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh19 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val19 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst19 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat19 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 445)
$Lbl_Attrib20 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type20 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag20 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh20 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val20 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst20 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat20 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
GuiSetCoord(10, 465)
$Lbl_Attrib21 = GUICtrlCreateLabel("", -1,-1, $Col_w1,20)
$Lbl_Type21 = GUICtrlCreateLabel("", 3, -1,$Col_w2,-1,1)
$Lbl_Flag21 = GUICtrlCreateLabel("", 3, -1, $Col_w3, -1,1)
$Lbl_Thresh21 = GUICtrlCreateLabel("", 3, -1, $Col_w4, -1,1)
$Lbl_Val21 = GUICtrlCreateLabel("", 3, -1, $Col_w5, -1,1)
$Lbl_Worst21 = GUICtrlCreateLabel("", 3, -1, $Col_w6, -1,1)
$Lbl_Stat21 = GUICtrlCreateLabel("", 3, -1, $Col_w7, -1,1)
$End = GUICtrlCreateDummy()
GuiSetCoord(240, 490)
$Btn_Chk = GUICtrlCreateButton("Check Drive", -1, -1, 80, 30)
$Lbl_Warn = GUICtrlCreateLabel( "", 40, -1, 120, 30, 1)
GUICtrlSetFont($Lbl_Warn, 14, 600)
GUICtrlSetColor($Lbl_Warn, 0xFF0000)
For $I = $Lbl_Attrib To $Lbl_Stat
   GUICtrlSetBkColor($I,0x00FFFF)
Next
;For $I = $Lbl_Attrib1 To $Lbl_Stat15
For $I = $Start+1 To $End-1
   GUICtrlSetBkColor($I, 0xBFFFB1)
Next
GUISetState()
While 1
   $Msg = GUIGetMsg()
   Switch $Msg
      Case -3
         Exit
      Case $Menu_TempC
         $iTempScale = -1
         $sTemp = "C"
         If NOT $iTempRef Then ContinueLoop
         GUICtrlSetData($iTempRef, _Temp_Convert($iTempScale))
      Case $Menu_TempF
         $iTempScale = 0
         $sTemp = "F"
         If NOT $iTempRef Then ContinueLoop
         GUICtrlSetData($iTempRef, _Temp_Convert($iTempScale))
      Case $Btn_Chk
         $Drive = GUICtrlRead($Combo_Dsel)
         $iTempRef = 0
         GUICtrlSetState($Btn_Chk, 144)
         For $I = $Start+1 To $End-1
            GUICtrlSetBkColor($I, 0xBFFFB1)
            GUICtrlSetData($I, "")
            GUICtrlSetColor($I, 0x000000)
         Next
         GUICtrlSetData($Lbl_Warn, "")
         GUICtrlSetData($Lbl_Proc, "Checking S.M.A.R.T. Data For Drive...  " & $Drive & "\")
         $SmartData = ""
         $SmartData = _GetSmartData($Drive)
         
         GUICtrlSetData($Lbl_Proc,"")
         If $smartData <> -1 then 
            $sLbl = $Start +1;$Lbl_Attrib1
            For $I = 1 To Ubound($smartData) -1
               For $J = 1 To 7
                  ;If $i = 11 AND $j = 5 Then
                  If StringInStr($smartData[$I][$j], "Temperature") Then $iTempRef = $sLbl +4
                  
                  If $sLbl = $iTempRef Then
                     ;If GUICtrlRead($Menu_TempF) = 65 Then
                     GUICtrlSetData($iTempRef, $smartData[$I][$J] & Chr(176) & " C")
                     If GUICtrlRead($Menu_TempF) = 65 Then GUICtrlSetData($iTempRef, _Temp_Convert(0))
                  Else
                     GUICtrlSetData($sLbl, $smartData[$I][$J])
                  EndIf
                  If $J = 7 AND $SmartData[$I][$J] = "NOT OK" Then
                     $rColor = 0xFAFCA0
                     $fColor = 0x000000
                     If $SmartData[$I][$J -5] = "Pre-Failure" Then
                        $rColor = 0xFFABFF
                        $fColor = 0xFF0000
                        $fWarn = True
                     EndIf
                     For $L = $sLbl -6 To $sLbl
                        GUICtrlSetBkColor($L, $rColor)
                        GUICtrlSetColor($L, $fColor)
                     Next
                  EndIf
                  $sLbl += 1
               Next
            Next
         Else
            Msgbox(0,"Problem checking drive","Unable to check drive " & $drive & "\" & @CRLF & "The drive may not be S.M.A.R.T. capable")
         EndIf
         GUICtrlSetState($Btn_Chk, 80)
         If $fWarn Then GUICtrlSetData($Lbl_Warn, "WARNING !")
   EndSwitch
Wend


Func _GetSmartData($vDrive  = "C:")
   If DriveStatus ( $vDrive ) <> "Ready" then 
      SetError(1)
      Return -1
   EndIf
   
   If StringLeft($vDrive,1) <> '"' then $vDrive = '"' & $vDrive
   If StringRight($vDrive,1) <> '"' then $vDrive &= '"'
   
   Local $iCnt, $iCheck, $vPartition,$vDeviceID,$vPNPID
   
   $vPartition = _LogicalToPartition ($vDrive)
   If $vPartition = -1 then Return -1
   
   $vDeviceID = _PartitionToPhysicalDriveID($vPartition)
   If $vDeviceID = -1 then Return -1
   
   $vPNPID = _PNPIDFromPhysicalDriveID($vDeviceID)
   If $vPNPID = -1 then Return -1
   
   $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\WMI")
   $oDict = ObjCreate("Scripting.Dictionary")
   
   $colItems1 = $objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_ATAPISmartData", "WQL", _
         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   
   $colItems2 = $objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_FailurePredictThresholds", "WQL", _
         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   
   $colItems3 = $objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_FailurePredictStatus", "WQL", _
         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   
   _CreateDict() ; Create Dictionary
   ;ConsoleWrite ($strComputer&@CR)							  
   
   $iCnt = 1
   For $objItem In $colItems1
      If StringLeft($objItem.InstanceName,StringLen($vPNPID)) = String($vPNPID) AND StringLeft($objItem.InstanceName, 3) = "ide" then 
         
         ;ConsoleWrite ("Active: " & $objItem.Active&@CR)
         ;ConsoleWrite ("Checksum: " & $objItem.Checksum&@CR)
         ;ConsoleWrite ("ErrorLogCapability: " & $objItem.ErrorLogCapability&@CR)
         ;ConsoleWrite ("ExtendedPollTimeInMinutes: " & $objItem.ExtendedPollTimeInMinutes&@CR)
         ;ConsoleWrite ("InstanceName: " & $objItem.InstanceName&@CR)
         ;ConsoleWrite ("Length: " & $objItem.Length&@CR)
         ;ConsoleWrite ("OfflineCollectCapability: " & $objItem.OfflineCollectCapability&@CR)
         ;ConsoleWrite ("OfflineCollectionStatus: " & $objItem.OfflineCollectionStatus&@CR)
         $strReserved = $objItem.Reserved
         ;ConsoleWrite ("Reserved: " & _ArrayToString($strReserved,",")&@CR)
         ;ConsoleWrite ("SelfTestStatus: " & $objItem.SelfTestStatus&@CR)
         ;ConsoleWrite ("ShortPollTimeInMinutes: " & $objItem.ShortPollTimeInMinutes&@CR)
         ;ConsoleWrite ("SmartCapability: " & $objItem.SmartCapability&@CR)
         ;ConsoleWrite ("TotalTime: " & $objItem.TotalTime&@CR)
         $strVendorSpecific = $objItem.VendorSpecific
         ;ConsoleWrite ("VendorSpecific: " & _ArrayToString($strVendorSpecific,",")&@CR)
         ;ConsoleWrite ("VendorSpecific2: " & $objItem.VendorSpecific2&@CR)
         ;ConsoleWrite ("VendorSpecific3: " & $objItem.VendorSpecific3&@CR)
         $strVendorSpecific4 = $objItem.VendorSpecific4
         ;ConsoleWrite ("VendorSpecific4: " & _ArrayToString($strVendorSpecific4,",")&@CR)
      Else
         
         $iCnt +=1
      EndIf
      
   Next
   
   
   $iCheck = 1
   For $objItem In $colItems2
      If $iCheck = $iCnt then 
         $strVendorSpecific2 = $objItem.VendorSpecific
         ;ConsoleWrite ("FailurePredictThresholds: " & _ArrayToString($strVendorSpecific2,",")&@CR)
      Else
         $iCheck +=1
      EndIf
   Next
   
   $iCheck = 1
   For $objItem In $colItems3
      If $iCheck = $iCnt then 
         $strVendorSpecific3 = $objItem.PredictFailure
         ;ConsoleWrite ("PredictFailure: " & $strVendorSpecific3&@CR)
         $strVendorSpecific3 = $objItem.Reason
         ;ConsoleWrite ("PredictReason: " & $strVendorSpecific4&@CR)
      Else
         $iCheck +=1
      EndIf
   Next
   
   If NOT IsArray($strVendorSpecific4) then Return -1 ;Not a Smart capable drive
   If NOT IsArray($strVendorSpecific2) then Return -1
   
   Dim $Status [22]
   For $i = 1 to 21
      $Status[$i] = "NOT OK" ;default all status to "NOT OK"
   Next
   
   ;if a status passes then Change it to OK
   If $strVendorSpecific[5] >= $strVendorSpecific2[3]  then $Status[1] = "OK"
   If $strVendorSpecific[17] >= $strVendorSpecific2[15] then $Status[2] = "OK"
   If $strVendorSpecific[29] >= $strVendorSpecific2[27] then $Status[3] = "OK"
   If $strVendorSpecific[41] >= $strVendorSpecific2[39] then $Status[4] = "OK"
   If $strVendorSpecific[53] >= $strVendorSpecific2[51] then $Status[5] = "OK"
   If $strVendorSpecific[65] >= $strVendorSpecific2[63] then $Status[6] = "OK"
   If $strVendorSpecific[77] >= $strVendorSpecific2[75] then $Status[7] = "OK"
   If $strVendorSpecific[89] >= $strVendorSpecific2[87] then $Status[8] = "OK"
   If $strVendorSpecific[101] >= $strVendorSpecific2[99] then $Status[9] = "OK"
   If $strVendorSpecific[113] >= $strVendorSpecific2[111] then $Status[10] = "OK"
   If $strVendorSpecific[125] >= $strVendorSpecific2[123] then $Status[11] = "OK"
   If $strVendorSpecific[137] >= $strVendorSpecific2[135] then $Status[12] = "OK"
   If $strVendorSpecific[149] >= $strVendorSpecific2[147] then $Status[13] = "OK"
   If $strVendorSpecific[161] >= $strVendorSpecific2[159] then $Status[14] = "OK"
   If $strVendorSpecific[173] >= $strVendorSpecific2[171] then $Status[15] = "OK"
   If $strVendorSpecific[185] >= $strVendorSpecific2[183] then $Status[16] = "OK"
   If $strVendorSpecific[197] >= $strVendorSpecific2[195] then $Status[17] = "OK"
   If $strVendorSpecific[206] >= $strVendorSpecific2[204] then $Status[18] = "OK"
   If $strVendorSpecific[218] >= $strVendorSpecific2[216] then $Status[19] = "OK"
   If $strVendorSpecific[230] >= $strVendorSpecific2[228] then $Status[20] = "OK"
   If $strVendorSpecific[242] >= $strVendorSpecific2[240] then $Status[21] = "OK"
   
   
   
   Dim $aSmartData[1][8] = [["ID","Attribute","Type","Flag","Threshold","Value","Worst","Status"]]
   $iCnt=1
   For $x = 2 to 242 Step 12 
      If $strVendorSpecific[$x] <> 0 then ;0 id is not valid for this Device
         $NextRow = Ubound($aSmartData)
         Redim $aSmartData[$NextRow +1][8]
         $aSmartData[$NextRow][0] = $strVendorSpecific[$x];ID
         $aSmartData[$NextRow][1] = $oDict.Item($strVendorSpecific[$x]);Attribute
         If $aSmartData[$NextRow][1] = "" then $aSmartData[$NextRow][1] = "Unknown SMART Attribute"
         
         If Mod($strVendorSpecific[$x +1],2) then ;Type If odd number then it is a pre-failure value
         $aSmartData[$NextRow][2] = "Pre-Failure" 
      Else
         $aSmartData[$NextRow][2] = "Advisory" 
      EndIf
      $aSmartData[$NextRow][3] = "0x" & Hex($strVendorSpecific[$x +1], 4);Flag
      $aSmartData[$NextRow][4] = $strVendorSpecific2[$x +1];Threshold
      $aSmartData[$NextRow][5] = $strVendorSpecific[$x +3];Value
      $aSmartData[$NextRow][6] = $strVendorSpecific[$x +4];Worst
      $aSmartData[$NextRow][7] = $Status[$iCnt];Status
   EndIf
      $iCnt+=1
   Next

   Return 	$aSmartData
EndFunc   ;<==> _GetSmartData($vDrive  = "C:")

Func _PartitionToPhysicalDriveID($vPart)
   
   $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
   $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDriveToDiskPartition", "WQL", _
         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   If IsObj($colItems) then
      For $objItem In $colItems
         If $objItem.Dependent == $vPart then 
            $vPdisk = $objItem.Antecedent
            $vPdisk = StringReplace(StringTrimLeft($vPdisk,Stringinstr($vPdisk,"=")),'"',"")
            $strDeviceID = StringReplace($vPdisk, "\\", "\")
            Return $strDeviceID
         Endif
      Next
   Endif
   Return -1
EndFunc   ;<==> _PartitionToPhysicalDriveID($vPart)

Func _PNPIDFromPhysicalDriveID($vDriveID)
   
   $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive WHERE MediaLoaded = -1", "WQL", _
         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   If IsObj($colItems) then
      For $objItem In $colItems
         If NOT StringRegExp($objItem.MediaType, "(?i)Fixed\s+hard\s+disk\s+media") Then Return -1
         If $objItem.DeviceID == $vDriveID then
            Return $objItem.PNPDeviceID
         EndIf
      Next
   Endif
   Return -1
EndFunc   ;<==> _PNPIDFromPhysicalDriveID($vDriveID)

Func _LogicalToPartition ($vDriveLet)
   Local $objWMIService,$colItems,$vAntecedent,$vPartition
   
   $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
   $colItems = $objWMIService.ExecQuery("SELECT Dependent,Antecedent FROM Win32_LogicalDiskToPartition", "WQL", _
         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   If IsObj($colItems) then
      For $objItem In $colItems
         If StringRight($objItem.Dependent,4) == $vDriveLet then 
            $vAntecedent=$objItem.Antecedent
            $Output &= $vDriveLet & "  =  " & StringRight($objItem.Dependent,4) & @CRLF
            Return $vAntecedent;$partition
         EndIf
      Next
   Endif
   Return -1
EndFunc   ;<==> _LogicalToPartition ($vDriveLet)


Func _CreateDict()
   $oDict.Add(1,"Read Error Rate")
   $oDict.Add(2,"Throughput Performance")
   $oDict.Add(3,"Spin-Up Time")
   $oDict.Add(4,"Start/Stop Count")
   $oDict.Add(5,"Reallocated Sectors Count")
   $oDict.Add(6,"Read Channel Margin")
   $oDict.Add(7,"Seek Error Rate Rate")
   $oDict.Add(8,"Seek Time Performance")
   $oDict.Add(9,"Power-On Hours (POH)")
   $oDict.Add(10,"Spin Retry Count")
   $oDict.Add(11,"Recalibration Retries")
   $oDict.Add(12,"Device Power Cycle Count")
   $oDict.Add(13,"Soft Read Error Rate")
   $oDict.Add(191,"G-Sense Error Rate Frequency")
   $oDict.Add(192,"Power-Off Park Count")
   $oDict.Add(193,"Load/Unload Cycle")
   $oDict.Add(194,"Temperature")
   $oDict.Add(195,"ECC Corrected Count")
   $oDict.Add(196,"Reallocated Event Count")
   $oDict.Add(197,"Current Pending Sector Count")
   $oDict.Add(198,"Uncorrectable Sector Count")
   $oDict.Add(199,"UltraDMA CRC Error Count")
   $oDict.Add(200,"Write Error Rate")
   $oDict.Add(201,"Soft Read Error Rate")
   $oDict.Add(202,"Address Mark Errors Frequency")
   $oDict.Add(203,"ECC errors (Maxtor: ECC Errors)")
   $oDict.Add(204, "Soft ECC Correction")
   $oDict.Add(205, "Thermal Asperity Rate (TAR)")
   $oDict.Add(206, "Flying Height")
   $oDict.Add(207, "Spin High Current")
   $oDict.Add(208, "Spin Buzz")
   $oDict.Add(209, "Offline Seek")
   $oDict.Add(220, "Disk Shift")
   $oDict.Add(221, "G-Sense Error Rate")
   $oDict.Add(222, "Loaded Hours")
   $oDict.Add(223, "Load/Unload Retry Count")
   $oDict.Add(224, "Load Friction")
   $oDict.Add(225, "/Unload Cycle Count")
   $oDict.Add(226, "Load 'In'-time")
   $oDict.Add(227, "Torque Amplification Count")
   $oDict.Add(228, "Power-Off Retract Cycle")
   $oDict.Add(230, "GMR Head Amplitude")
   $oDict.Add(231, "Temperature")
   $oDict.Add(240, "Head Flying Hours")
   $oDict.Add(250, "Read Error Retry Rate")
EndFunc   ;<==> _CreateDict()

Func _ArrayToString(Const ByRef $avArray, $sDelim = "|", $iStart = 0, $iEnd = 0)
	If Not IsArray($avArray) Then Return SetError(1, 0, "")

	Local $sResult, $iUBound = UBound($avArray) - 1

	; Bounds checking
	If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
	If $iStart < 0 Then $iStart = 0
	If $iStart > $iEnd Then Return SetError(2, 0, "")

	; Combine
	For $i = $iStart To $iEnd
		$sResult &= $avArray[$i] & $sDelim
	Next

	Return StringTrimRight($sResult, StringLen($sDelim))
EndFunc   ;==>_ArrayToString

Func _Temp_Convert($iScale = -1)
   Local $iCurrent = GUICtrlRead($iTempRef), $iVal
   If $iCurrent = "" OR $iTempRef = 0 Then Return
   If $iScale <> -1 Then $iScale = 0
   If $iScale = -1 Then
      If StringInStr($iCurrent, "C") Then Return $iCurrent
      $iVal = StringRegExp($iCurrent,"(?i).?\d+", 1)
      $iCurrent = $iVal[0]
      $iCurrent = Round((5/9)*($iCurrent -32)) & Chr(176) & " C"
   Else
      If StringInStr($iCurrent, "F") Then Return $iCurrent
      $iVal = StringRegExp($iCurrent,"(?i).?\d+", 1)
      $iCurrent = $iVal[0]
      $iCurrent = Round((9/5)* $iCurrent +32) & Chr(176) & " F"
   EndIf
   Return $iCurrent
EndFunc

;This is COM error handler
Func MyErrFunc()
   $HexNumber=hex($oMyError.number,8)
   Return
   Msgbox(0,"COM Error Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
         "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
         "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
         "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
         "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
         "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
         "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
         "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
         "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
         )
   SetError(1)  ; to check for after this function returns
Endfunc   ;<==> MyErrFunc()