Antivirus Diagnostics Report

Started by Deana, October 24, 2013, 03:31:50 PM

Previous topic - Next topic

Deana

Code (winbatch) Select
;***************************************************************************
;**   Antivirus Diagnostics Report
;**
;** Purpose: Obtains Antivirus Diagnostics into HTML file and optionally displays or emails the results.
;** Inputs:  SMTP server information as variables
;** Outputs: Optionally displays or emails the results.
;** System Requirements: Postie Extender. WinBatch 2010B or newer.
;**
;** Developer: Deana Falk 2013.10.24
;***************************************************************************
If Version( )< '2010B'
   Pause('Notice', 'Need 2010B or Newer Version of WinBatch')
   Exit
EndIf
ver = WinVersion( 5 )

#DefineFunction udfWMIDataArray( class, properties, root )
   ParseData( StrReplace( properties, ',', ' ' )  )
   propcount = param0
   arrData = ArrDimension(2, propcount)
   ArrInitialize(arrData, 'NA')
   strComputer = "."
   query = "Select * from " : class
   objWMIService = GetObject("winmgmts:\\" : strComputer : root)
   colItems = objWMIService.ExecQuery(query)
   instcount = colitems.Count
   instance = 1
   ForEach objItem In colItems
      If ObjectTypeGet(objItem)=="EMPTY" Then Continue
      For i=0 To param0-1
         n = i+1
         propname = param%n%
         arrData[0,i] = propname
         arrData[instance,i] = objItem.%propname%
      Next
      ; Handle multiple instances
      If instcount > instance
         ArrayRedim( arrData, ArrInfo(arrData,1)+1, -1 )
         instance = instance+1
      EndIf
   Next
   Return arrData
#EndFunction

#DefineFunction udfConvertToHTMLTable( arrData )
   rowcount = ArrInfo( arrData, 1 )
   colcount = ArrInfo( arrData, 2 )
   htmlData = '<table width="500" border="1">'
   ;Pause( rowcount, colcount)
   For row = 0 To ArrInfo( arrData, 1 ) - 1
       htmlData = htmlData : '<tr>'
       For col = 0 To ArrInfo( arrData, 2 ) - 1
          htmlData = htmlData : '<td>'
          If ObjectTypeGet( arrData[row,col] ) == 'ARRAY|VARIANT'
              data = udfArrayToList(arrData[row,col],'|')
          Else
              data = arrData[row,col]
          EndIf
          htmlData = htmlData : data
          htmlData = htmlData : '</td>'
       Next
       htmlData = htmlData : '</tr>'
   Next
   htmlData = htmlData : '</table>'
   Return htmlData
#EndFunction


#DefineFunction udfConvertToHTMLTableEx( arrData )
   ; Beautified version of the table
   rowcount = ArrInfo( arrData, 1 )
   colcount = ArrInfo( arrData, 2 )
   htmlData = '<table width="auto" border="1" cellpadding="3" cellspacing="0">'
   ;Pause( rowcount, colcount)
   For row = 0 To ArrInfo( arrData, 1 ) - 1
       ; Alternate Row Color
       If row == 0 ;Heading only
          htmlData = htmlData : '<tr bgcolor="CornflowerBlue">' ; #6495ED
       ElseIf (row mod 2) == 0      ;even numbered row
          htmlData = htmlData : '<tr bgcolor="LightGray">' ;   #D3D3D3
       Else
          htmlData = htmlData : '<tr>'
       EndIf
       For col = 0 To ArrInfo( arrData, 2 ) - 1
                    htmlData = htmlData : '<td align="left">'
          If ObjectTypeGet( arrData[row,col] ) == 'ARRAY|VARIANT'
              data = udfArrayToList(arrData[row,col],'|')
          Else
              data = arrData[row,col]
          EndIf
          htmlData = htmlData : data
          htmlData = htmlData : '</td>'
       Next
       htmlData = htmlData : '</tr>'
   Next
   htmlData = htmlData : '</table>'
   Return htmlData
#EndFunction

#DefineFunction udfArrayToList(arrData,strDelim)
   strData = ''
   count = ArrInfo ( arrData, 1 ) -1
   For ctr = 0 To count
      If ctr < count
         strData=StrCat(strData,arrData[ctr],strDelim)
      Else
         strData=StrCat(strData,arrData[ctr])
      EndIf
   Next
   Return (strData)
#EndFunction

; System Info
computername = ComputerNameGet(0)
username = Environment( 'USERNAME' )
dir = ShortCutDir( 'Personal' ,0 ,1 )

; MODIFY TO FIT YOUR NEEDS
title = 'Antivirus Diagnostics Report'
; Email Settings
smtphost = ";mail.dadomain.com"
toaddr = "dauser@dadomain.com"
fromaddr = username : "@dadomain.com"


subject = "Hardware Info for": computername
mymsg="<html><head><title>Antivirus Diagnostics Report</title></head><body><h1>":subject:"</h1>See attached.</body></html>"
flags="h"
attachment = dir: computername : ".html"




; HTML Output
fh = FileOpen( attachment, "Write")
FileWrite( fh, '<!DOCTYPE html><html><head><title>Antivirus Information for computername</title><head><body><h1>':computername:'</h1>' )


heading = 'AntivirusProduct'
class = 'AntivirusProduct'
properties = 'Name,Manufacturer,Product,SerialNumber,Status'
If ver >= "2-6-0" ;Vista or newer
   properties  =  'DisplayName,productState,instanceGuid,pathToSignedProductExe,pathToSignedReportingExe'
Else ;XP
   properties  =  'DisplayName,onAccessScanningEnabled,productState,productUptoDate,VersionNumber'
Endif
root =  '\root\SecurityCenter2'
arrData = udfWMIDataArray( class, properties, root )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )



; Finalize HTML
FileWrite( fh, '</body></html>' )
FileClose( fh )


ret = AskYesNo( title, 'Would you like to display the results?' )
If ret
   ; Display Results
   Run( attachment, '' )
EndIf

ret = AskYesNo( title, 'Would you like to EMAIL the results?' )
If ret
   ; EMAIL Results
   AddExtender("WWPST44I.DLL")
   kInit(smtphost,fromaddr,"","","")
   kDest(toaddr,"","")
   ;ret = kSendText(subject,mymsg,attachment,"h")
   ret = kSendFile(subject,attachment,attachment,flags)
   If ret == 0
      errline=kStatusInfo()
      Message("ErrLine",errline)
   EndIf
EndIf

Exit
Deana F.
Technical Support
Wilson WindowWare Inc.

td

Looks like some kind of paste error.  A part of the script seem to be missing.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Deana

Quote from: td on October 25, 2013, 06:40:24 AM
Looks like some kind of paste error.  A part of the script seem to be missing.

Thanks. It was a missing end bracket on {code=winbatch
Deana F.
Technical Support
Wilson WindowWare Inc.