summaryrefslogtreecommitdiff
path: root/antivirusDetection.vbs
diff options
context:
space:
mode:
authorMichel Thomas <michelphoenix98@gmail.com>2020-02-11 21:34:57 +0530
committerMike Kaganski <mike.kaganski@collabora.com>2020-02-12 09:14:03 +0100
commit8d8f62852a64bd2fcae47a9499406d9167aebf83 (patch)
treefb350383c96c6cb1e70a334c2aed3ea34d284218 /antivirusDetection.vbs
parenta7d1fed24557b203acb5016a98af26f4ef24d27a (diff)
tdf#84553 Correctly handle failures while getting a WMI Object.
The output before this patch : checking for active Antivirus software... C:\cygwin\home\tdf\lode\jenkins\workspace\gerrit_windows\antivirusDetection.vbs(1, 1) (null): 0x8004100E found The link for which is : https://ci.libreoffice.org/job/gerrit_windows/57035/consoleFull Change-Id: I714442739a8daf132e95b9f6a750aa7abab3561e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88465 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'antivirusDetection.vbs')
-rwxr-xr-xantivirusDetection.vbs30
1 files changed, 18 insertions, 12 deletions
diff --git a/antivirusDetection.vbs b/antivirusDetection.vbs
index a4e76731f0b6..ad22e267343d 100755
--- a/antivirusDetection.vbs
+++ b/antivirusDetection.vbs
@@ -1,19 +1,25 @@
+On Error Resume Next
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\SecurityCenter2")
-Set installedAntiviruses = objWMIService.ExecQuery("Select * from AntivirusProduct")
+If objWMIService is Nothing Then
+ Wscript.StdOut.Write "NULL"
+Else
+ Set installedAntiviruses = objWMIService.ExecQuery("Select * from AntivirusProduct")
'Iterates through all the antivirus software,retrieved by the WMI query,present on the system and prints only the ones that are active
'this is done by checking the 12th bit of the productState property of the antivirus
'if 12th bit is on then it means that the antivirus is in active state
'if 12th bit is off then it is inactive.
'see http://neophob.com/2010/03/wmi-query-windows-securitycenter2/
-count=0
-list=""
-For Each antivirus in installedAntiviruses
- If antivirus.productState And &h01000 Then 'checking the state of the 12th bit of productState property of the antivirus
- count=count+1
- list=list & VBNewLine & VBtab & "*" & antivirus.displayName
+ count=0
+ list=""
+ For Each antivirus in installedAntiviruses
+ If antivirus.productState And &h01000 Then 'checking the state of the 12th bit of productState property of the antivirus
+ count=count+1
+ list=list & VBNewLine & VBtab & "*" & antivirus.displayName
+ End if
+ Next
+ If count = 0 Then
+ Wscript.StdOut.Write "NOT_FOUND"
+ Else
+ Wscript.Echo list
End if
-Next
-If count = 0 Then
- Wscript.StdOut.Write "NOT_FOUND"
-Else Wscript.Echo list
-End if
+End if \ No newline at end of file