Bettylou Posted January 20, 2017 Share Posted January 20, 2017 On a vista system this code printed out Quote MsgBox(0, "", $aResult0 & "'s product state is indeterminate") Will adding COM error handling correct it? expandcollapse popupLocal $aResult0, $aResult1, $ProductIsInOrOutOfDate, $ProductDisabledOrNot $oWMI = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\localhost\root\SecurityCenter2") $colItems = $oWMI.ExecQuery("Select * from AntiVirusProduct") For $objAntiVirusProduct In $colItems $aResult0 = $objAntiVirusProduct.DisplayName $aResult1 = $objAntiVirusProduct.ProductState $ProductIsInOrOutOfDate = StringMid(Hex($aResult1), 7, 2) $ProductDisabledOrNot = StringMid(Hex($aResult1), 5, 2) If @error Then MsgBox(0, "", "Warning! *No AntiVirus Installed*" & @CRLF) Else Switch $ProductDisabledOrNot Case "10", "11" MsgBox(0, "", $aResult0 & " " & "(Enabled & " & (($ProductIsInOrOutOfDate = "10") ? "Not " : "") & "up-to-date)") Case "00", "01" MsgBox(0, "", $aResult0 & " " & "(Disabled & " & (($ProductIsInOrOutOfDate = "10") ? "Not " : "") & "up-to-date)") Case Else MsgBox(0, "", $aResult0 & "'s product state is indeterminate") EndSwitch EndIf Next If $aResult0 Then Exit $colItems = $oWMI.ExecQuery("Select * from AntispywareProduct") For $objAntiSpywareProduct In $colItems $aResult0 = $objAntiSpywareProduct.DisplayName $aResult1 = $objAntispywareProduct.ProductState $ProductIsInOrOutOfDate = StringMid(Hex($aResult1), 7, 2) $ProductDisabledOrNot = StringMid(Hex($aResult1), 5, 2) If @error Then MsgBox(0, "", "Warning! *No AntiVirus Installed*" & @CRLF) Else Switch $ProductDisabledOrNot Case "10", "11" MsgBox(0, "", $aResult0 & " " & "(Enabled & " & (($ProductIsInOrOutOfDate = "10") ? "Not " : "") & "up-to-date)") Case "00", "01" MsgBox(0, "", $aResult0 & " " & "(Disabled & " & (($ProductIsInOrOutOfDate = "10") ? "Not " : "") & "up-to-date)") Case Else MsgBox(0, "", $aResult0 & "'s product state is indeterminate") EndSwitch EndIf Next Link to comment Share on other sites More sharing options...
ripdad Posted January 21, 2017 Share Posted January 21, 2017 I don't have a Vista machine, but I will attempt to help... 1. You should always use a COM Error Handler when you work with objects. 2. If you are getting other information like DisplayName - then no, it won't help with other results. 3. What is the RAW data from DisplayName and ProductState ? 4. You may need to insert #RequireAdmin at the very top of your script. Give me a hour or so and I'll rework your script with error handling. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
ripdad Posted January 21, 2017 Share Posted January 21, 2017 (edited) Not tested, but should work. Please read the notes in the script. expandcollapse popup#RequireAdmin Opt('MustDeclareVars', 1) ; Local $_objError = ObjEvent('AutoIt.Error', '_ObjErrorHandler') ; Local $sReturn = _SC2_AntiVirus() Local $nError = @error If $nError Then MsgBox(0, 'Error: ' & $nError, $sReturn) Else MsgBox(0, 'Results', $sReturn) EndIf ; Func _SC2_AntiVirus() Local $objWMI = ObjGet('Winmgmts:{ImpersonationLevel=Impersonate,AuthenticationLevel=PktPrivacy,(Debug,Security)}!\\localhost\root\SecurityCenter2') Local $colItems = $objWMI.ExecQuery('Select * from AntiVirusProduct') Local $NumberOfObjects = $colItems.Count If @error Or $NumberOfObjects = 0 Then Return SetError(-1, 0, 'Object Not Found - No Data Available'); <-- This will tell you if AV is not installed EndIf ; Local $sDisplayName, $nProductState, $ProductIsInOrOutOfDate, $ProductDisabledOrNot, $str = '' ; For $objAntiVirusProduct In $colItems $sDisplayName = $objAntiVirusProduct.DisplayName $nProductState = $objAntiVirusProduct.ProductState $ProductIsInOrOutOfDate = StringMid(Hex($nProductState), 7, 2) $ProductDisabledOrNot = StringMid(Hex($nProductState), 5, 2) Switch $ProductDisabledOrNot Case '10', '11' $str &= $sDisplayName & " (Enabled & " & (($ProductIsInOrOutOfDate = "10") ? "Not " : "") & "up-to-date)" Case '00', '01' $str &= $sDisplayName & " (Disabled & " & (($ProductIsInOrOutOfDate = "10") ? "Not " : "") & "up-to-date)" Case Else $str &= $sDisplayName & "'s product state is indeterminate" EndSwitch $str &= @CRLF Next Return $str EndFunc ; ; Minimal COM Error Handler Func _ObjErrorHandler($_objError) $_objError.Clear Return SetError(1) EndFunc ; Edited January 22, 2017 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Bettylou Posted January 21, 2017 Author Share Posted January 21, 2017 (edited) Thanks ripdad. I also don't have access to a Vista system however, I ran it on my win 10 64X and it printed out win defender but not Avast which is installed and UTD. I'll keep working on it. Edited January 21, 2017 by Bettylou Link to comment Share on other sites More sharing options...
ripdad Posted January 22, 2017 Share Posted January 22, 2017 I modified the script to handle multiple instances. Try again. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Bettylou Posted January 24, 2017 Author Share Posted January 24, 2017 Thanks ripdad. Now it works. Link to comment Share on other sites More sharing options...
ripdad Posted January 24, 2017 Share Posted January 24, 2017 Good, glad to hear it. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now