Link to home
Start Free TrialLog in
Avatar of cgooden01
cgooden01Flag for United States of America

asked on

Trying to have this VBScript to pull Norton Antivirus Product Version and Virus Definition Date

Been at this for some time now, everything is working just fine as i run this script but can not get the field of Norton Product Version and Virus Definition Date.  Being mind boggled with this, seeing that im not an expert in scripting, i have tried every option i know and could find on the net.  
'~~[script version]~~
'version 2.12a
'~~[/script version]~~
'
'~~[usage]~~
'shealth.vbs (manual mode)
'shealth.vbs list:""
'shealth.vbs .\servers.txt' (this uses the email address specified here 
' in the SMTPmailto variable)
'~~[/usage]~~
'
'Single server checks:
' I included an inputbox if no command-line options are specified for running against a 
' single server and prompt for email address if you wanted to run it against a single 
' server and email to a recipient afterwards.
'
'Commandline functionality: 
' You can use either this format: 
' shealth.vbs list:""
' or this: 
' shealth.vbs c:\temp\audit\servers.txt
'
' The second option will automatically mail the results to the SMTPMailto recipient. (if 
' blnsendsummary = true).
 
'Email functionality: 
' I have added an email functionality to the script so that after completion
' email will be sent to the user(s) specified in strMailto. You will receive an overview
' listing of servers and a column that will show 'warnings' - i.e. services that didn't start
' or if AV isn't installed and a column with the time that the particular server was scanned.
' Obviously, I could have gone much farther with this, but this is all I had time to do in 
' a pinch.
'
'Central output of summary files: 
' This also has been modified to write the output of each server to a file share, 
' (in addition to the files that are created (by default) to the 'results' folder where this 
' script resides. When a summary email made against multiple servers is sent, it points 
' back to that folder for the output. You just need to make sure that everyone who will 
' be receiving the emails has permissions to the folder.
'
' The results folder is the central repository where each server summary is saved, prior
' to being copied to the remote share. The script will copy the files out to the remote 
' share (strDestFolder) that you specify in the script if you select the email mode.
'
'Log file during script processing: 
' In the logs folder (which resides in the same folder that this script resides in), you'll
' find a log for each time the script was ran. This is useful if the script is erroring out
' and you can't figure out why.
'
'If you run this in manual mode (only one server inputted by double-clicking the script),
' and select 'email', it will email the overall health page of the individual server 
' rather than a summary page.
'
'If you run this in manual mode and you don't choose the email mode, it will open up the
' health page upon completion.
'
'Some other changes:
'
'Event Log entries (how many days back): 
' Modified the event log listing to show both warnings and errors. You can adjust the variable
' "IntDaysBack" to produce more event log entries... 
'
'Event Log entries (how many entries to show): 
' Also edit "strEventCount". 
'
'NOTE: If your query reports back the total amount of events specified in "strEventCount"
' before it is able to query all of the days specified in "IntDaysBack", then the script will
' move on to the next server, and you will only see the first "strEventCount" events found, 
' even though you know you have more events that aren't shown for days further back. This
' is by design.
'
'Drive threshholds: 
' You can change the "intFreeSpaceThreshold" to determine what is a critical threshold
' - - - if the threshhold is reached, then it will produce a warning on the summary page that
' is emailed (if multiple servers are scanned). If one server is scanned, it merely changes
' the color of the freespace text on the health page.
'
'Before your run this:
'Be sure to modify the SMTP server variable below with the IP address of the server that
' you are using. Also, edit strMailto, strMailfrom, and sourcefile if you are running this 
' against a list of servers. Some of these are superceded by command-line arguments.
'
'Other flavors of AV: 
' Check the function chkopsys(strComp) to find where to modify the reg keys values you are 
' checking for AV install status for other brands of AV. You may need to play with this 
' a bit to get it to work with other flavors.
 
'Feel free to post if you have any trouble. 
'~~[/comment]~~
 
'~~[script]~~
'========================
'
' Title: Server Check Script
'
' Filename: servchk.vbs
' Author: Leslie Maclachlan
' Modified by: Ariston Collander, Cox Computer Service
' Modified beyond all recognition by: Rob Dunn
'
'========================
On Error GoTo 0
'==System variables - dont change==
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2
Const ForReading = 1
Const ForAppending = 8
Const cdoSendUsingMethod = "", _
cdoSendUsingPort = 2, _
cdoSMTPServer = ""
 
Dim strScriptPath, strMessage, Count, strBgcolor, IntDebug, blnErrors, strMsg, objargs, strWarnings
Dim blnServices, blnDiskSpace, blnAV, blnEvents, strValue, blnSend, strComputer, StrComp, blnOnline
Dim strReadFromFile, strEventCount, strSpace, strService, strAntiVirus, intVirusDefAge
Dim summaryfile, intAV, l, ws, strSourceFile, strBootTime
'below variables for progress indicators
 
Dim objShell, objProcessEnv, objSystemEnv, objNet, objFso, objSwitches, WShSysEnv, WshShell
Dim query, item, acounter, blnExtendedWMI, blnProcessEvents
Dim dlgBarWidth, dlgBarHeight, dlgBarTop, dlgBarLeft, dlgProgBarWidth, dlgProgBarHeight 
Dim dlgProgBarTop, dlgProgBarLeft
Dim dlgBar, dlgProgBar, wdBar, objPBar, objBar, blnSearchWildcard
Dim blnProgressMode, blnDebugMode, dbgTitle
Dim dbgToolBar, dbgStatusBar, dbgResizable
Dim IE, objDIV, objDBG, strMyDocPath, strSubFolder, strTempFile, f1, ts, File2Load, objFlash
Dim dbgWidth, dbgHeight, dbgLeft, dbgTop, dbgVisible, strDestFolder1, strHideRows
Dim strIPAddress
 
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
Set objArgs = WScript.Arguments
Set ws = wscript.CreateObject("Scripting.FileSystemObject")
 
strScriptPath = replace(wscript.scriptfullname,"\" & wscript.scriptname,"")
resultsfolder = strScriptPath & "\results"
logfolder = strScriptPath & "\logs"
logfile = logfolder & "\" & replace(Date,"/","_") & "-" & replace(Time,":","'") & " server health.txt"
MakeSureDirectoryTreeExists(logfolder)
'wscript.echo resultsfolder
MakeSureDirectoryTreeExists(resultsfolder)
Set l = ws.OpenTextFile (logfile, ForAppending, True)
l.writeline "************************************************"
l.writeline "Server Health script executed at " & Now
 
'above variables for progress indicators
 
IntDebug = 0
 
 
'==Configure User defined Variables==
CurrentDate = Now
strMailto = ""     
'who are you mailing to? Input mode only. Command-line 
' parameters take precedence
 
strMailFrom = ""     'reply address, full mail address
strSMTPServer = ""     'set SMTP email server address here, ip address
 
SourceFile = "Z:\Audit\servers.txt"
'Where is the master list of servers being pulled from?
' For input mode only. Command-line parameters take precedence
 
bgcolor0 = "white"        'Colors for computer health page
bgcolor1 = "aliceblue"
strSummaryFileName = "summary.htm"
 
intAV = 1       '0 = McAfee VirusScan Enterprise
                '1 = Norton Antivirus
                '2 = Trend Officescan
                'Need people to test this (NAV)
'Event Log variable(s)
IntDaysBack = 1 'how many days prior you would like to pull event log entries from
 
strEventCount = 10        'Amount of events you want to count. If this number is 
    ' exceeded, then the script will stop checking events and move on to the next 
    ' server. This is useful if you have a LOT of errors, but want to quickly 
    ' scan the servers without holding up the entire process. If you have more 
    ' events that occurred in the last 2 days (for example) than what you have 
    ' specified here, you will only see the most recent events that fall within
    ' this count.
 
Set ws = CreateObject ("Scripting.FileSystemObject")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
 
blnSendMail = false 'send individual mails for each server checked - server list mode only.
blnCopyFile = true 'copy the summary files to a remote path - server list mode only.
 
strDestFolder = "Z:\Audit" 
            ' add ---> & WeekdayName(weekday(now)) 'to retain daily backups
            ' This is the remote path to copy files to, when run against server 
            ' list ONLY
 
intFreeSpaceThreshold = 10 'set critical threshold for drive space (shows up in red if free
            'percentage is lower than this number)
 
intVirusDefAge = 10     'set how many days back you might consider the virus definitions to be 
            ' too old.
 
blnSendSummary = true     'send a single summary email after everything is all done? (when running
             ' against server list ONLY
 
strCheckAccount = ""     'type a string of text that you wish to check your services against.
                ' for example, if you are phasing out old accounts or domains, the 
                ' script will generate an alert if it finds that a service is starting
                ' with credentials that contain this string.
                ' If you don't want to process this value, just set the variable to ""
                
'------------------
'End of User-configurable variables
'------------------
 
'Finds name of computer running the script
strSourceComputer = WshShell.ExpandEnvironmentStrings("%computername%")
'Finds source credentials of account running the script
strSourceDomain = WshShell.ExpandEnvironmentStrings("%userdomain%")
strSourceUser = WshShell.ExpandEnvironmentStrings("%username%")
 
blnSkipComputer = false 'do not modify
strReadFromFile = "yes"
 
If objargs.count < 1 Then
    Call fctInput
Else
    'strSourceFile = Chr(34) & objargs(0) & Chr(34)
 
    'wscript.echo strSourceFile
 
For I = 0 to objArgs.Count - 1
 
If InStr(1,LCase(objargs(I)),"list:") Then
    strMDArray = split(objargs(I),"list:") 
    'set sourcefile to be what follows the ':'
    SourceFile = replace(strMDArray(1),Chr(34),"")
    blnOK1 = true
l.writeline time & " - Pulling source listing from " & SourceFile
Set objTextFile = objFSO.OpenTextFile(sourcefile, ForReading)
 
ElseIf InStr(1,LCase(objargs(I)),"computer:") Then
    strMDArray = split(objargs(I),"computer:")
    strReadFromFile = "no"
    blnSendMail = true
    blnSend = true
    blnSendSummary = false
 
    'set sourcefile to be what follows the ':'
    strComputer = replace(strMDArray(1),Chr(34),"")
    blnOK1 = true
l.writeline time & " - Server specified: " & strComputer
 
ElseIf InStr(1,LCase(objargs(I)),"email:") Then
    strMDArray = split(objargs(I),"email:") 
    'set sourcefile to be what follows the ':'
    strMailTo = strMDArray(1)
    blnOK2 = true
    l.writeline Time & " - Email recipient specified as " & strMailto
Else
    sourcefile = objargs(0)
l.writeline time & " - Pulling source listing from " & SourceFile
Set objTextFile = objFSO.OpenTextFile(sourcefile, ForReading)
 
End If
Next
 
End If
 
If IntDebug = 0 then On Error Resume Next
 
IntCopyCount = 0
CutOff = Date() - 1 
Count = 0
strHDRColor1 = "'#AACFE4'"
strHDRColor2 = "'#6E8BB6'"
strFontColor1 = "'white'"
strFontColor2 = "'black'"
strFontStyle = "'Tahoma'"
strBodyBGColor = "'aliceblue'"
blnProgressMode = true
 
 
'wscript.echo "Calling IEStatus - blnProgressMode is: " & blnProgressMode
 
If objargs.count < 1 Then Call IEStatus
 
'strServerTable = "<Table border=1 width='100%'><tr><td bgcolor=" & strHDRColor2 _
' & "><font color=" & strFontColor1 & " face=" & strFontStyle & " size='2'>Computer </font></td>" _
' & "<td bgcolor=" & strHDRColor2 & "><font color=" & strFontColor1 & " face=" & strFontStyle & " size='2'>Warnings</font></td>" _
' & "<td bgcolor=" & strHDRColor2 & "><font color=" & strFontColor1 & " face=" & strFontStyle & " size='2'>Booted</font></td>" _ 
' & "<td bgcolor=" & strHDRColor2 & "><font color=" & strFontColor1 & " face=" & strFontStyle & " size='2'>Scanned</font></tr>"
strServerTable = "<font face=" & strFontStyle & " size='3'><strong>Server Health Check " _
& Now & "</strong></font><Table border=0 cellspacing=0 width='100%'><tr>" _
& "<td colspan='33%' bgcolor=" & strHDRColor2 & "><font color=" & strFontColor1 & " face=" & strFontStyle & " size='2'><strong>Warnings</strong></font></td>" _
& "<td colspan='33%' bgcolor=" & strHDRColor2 & "><font color=" & strFontColor1 & " face=" & strFontStyle & " size='2'><strong>Booted</strong></font></td>" _ 
& "<td colspan='33%' bgcolor=" & strHDRColor2 & "><font color=" & strFontColor1 & " face=" & strFontStyle & " size='2'><strong>Scanned</strong></font></td></tr></table>"
 
strEndTable = "</table>"
strBeginLine = "<TD><font face=" & strFontStyle & " color=" & strFontColor2 & " size=1>"
strMiddleLine = "</TD><TD><font face=" & strFontStyle & " color=" & strFontColor2 & " size=1>"
strEndLine = "</FONT></TD>"
 
l.writeline time & " - Generating HTML for server tables..."
'wscript.echo strServertable
 
If IntDebug = 0 then On Error Resume Next
 
 
'wscript.echo strReadfromFile
If strReadFromFile = "yes" Then 
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    
 
    Call ReadTextFile
Else
    objDictionary.Add 0, strComputer
End If
 
 
'==Assign each item in the text file to the Dictionary object==
For Each objItem in objDictionary
 
'===Assign each item in Dictionary to strComputer variable===
strWarnings = ""
blnServices = false
blnOnline = true
blnDiskSpace = false
blnEvents = false
blnAV = false
blnErrors = false
strBootTime = ""
strIPAddress = ""
strComputer = objDictionary.Item(objItem)
'wscript.echo strComputer
blnSkipComputer = false
strMsg = "<font face=" & strFontStyle & " color=" & strFontColor2 & ">Checking computer ["_
& strComputer & "]</font> <br>"
If dbgTitle <> "" Then objdiv.innerhtml = strMsg
l.writeline time & " - Now running check against " & strComputer
'===Assign results file===
resultsfile = resultsfolder & "\" & strComputer & ".htm "
 
'===Assign resultsfile to res variable===
l.writeline time & " - Generating output file: " & resultsfile
Set res = objFSO.CreateTextFile(resultsfile, True)
 
'===Create the HTML code for results file===
res.Writeline ("<html>")
res.Writeline ("<body bgcolor=" & strBodyBGColor & ">")
res.Writeline ("<h1><font face='arial' size='2'>Server check performed for computer [" & strComputer & "]: <font color='" & strFontColor1 & "'>" & Now & "</font></h1>")
'===Run the checks function===
Call checks(strComputer)
l.writeline time & " - Now running main check routine"
 
If blnSkipComputer = true Then
    l.writeline Now & ": skipping " & strComputer & ". This computer is either not accessible via " _
     & "this script or is not powered on."
    l.writeline time & " - Generating warnings..."
    Call fctWarnings
    l.writeline time & " - Generating email body..."
    Call WriteMail
Else
    If blnCopyFile = true then 
     strDestFolder1 = strDestFolder & "\" & strComputer
l.writeline time & " - Verifying that " & strDestFolder1 & " exists..."
 
     MakeSureDirectoryTreeExists(strDestFolder1) 
 
l.writeline time & " - Generating warnings..."
Call fctWarnings
     
     l.writeline time & " - Copying file from " & resultsfile & " to " & strDestfolder1
     Call fctCopyFile(resultsfile,strDestFolder1)
 
    Else
        strServerTable = ""
    End If
 
If blnSend = true Then
 
     If blnSendMail = true then 
 
         Call Sendmail(strMailTo,strMailFrom,"[Server health] - " & ucase(strComputer) & " health report",strMessage) 
     'strServerTable = ""
     End If
 
 
    End If
End If
tempvar = split(sourcefile,"\")
tempvar1 = UBound(tempvar) 
'wscript.echo tempvar(tempvar1)
On Error GoTo 0
summaryfile = strDestFolder & "\" & replace(tempvar(tempvar1),".txt","") & "_" & strSummaryFileName
'wscript.echo summaryfile
Call WriteSummary
 
blnskipcomputer = false
 
Next
 
'strServerTable = StrServerTable & StrEndTable
 
If blnSendSummary = true then 
    If strReadFromFile = "no" Then 
        SourceFile = "(computername specified: " & strComputer & ")"
        
    Else
         SourceFile = "<a href='" & SourceFile & "'>" & SourceFile & "</a>"
    End If
    strServerTable = strServerTable & "<br><font face=" & strFontStyle & " size='2'>" _
     & "This file is also located here: <a href='" & summaryfile & "'>" & SummaryFile & "</a><br>" _
     & "<font face=" & strFontStyle & " size='1'>output generated by Server Health Script " & strScriptVer _
     & "</font>"
    strMessage = "<font face=" & strFontStyle & " size='2'> Server health script " _
     & "completed at " & Now & ". Please check <a href='" & strDestFolder & "'>" _
     & strDestFolder & "</a> to view the server files. <br><br>You may also click the server name below to " _ 
     & "review each server's health stats directly.<br><br><strong>Listing generated by: </strong><br>" _
     & "Computer: " & strSourceComputer & "<br> User Credentials: " & strSourceDomain & "\" & strSourceUser _
     & "<br>Script path: " & strScriptPath & "\" & wscript.scriptname & "<br><br>Source server listing " _ 
     & "was pulled from " & replace(SourceFile,Chr(34),"") & "</font><br><br>" & strServerTable
    If InStr(sourcefile,"\") Then 
     myarray = split(sourcefile,"\")
     For i = 0 to UBound(myarray)
        
         sourcefile1 = replace(myarray(i),"</a>","")
     Next
    Else 
     sourcefile1 = strComputer
    End If
    Call SendMail(strMailFrom,strMailto,"[Server health] - " & sourcefile1,strMessage)
End If
'WScript.echo ("Complete")
If dbgTitle <> "" Then objDIV.InnerHTML = "<font face=" & strFontStyle & " color=" & strFontColor2& ">Server query completed at " & Now & "</font>" 
 
On Error GoTo 0
If blnSend = 0 and blnSendSummary = false Then
l.writeline Now & " - no email will be sent, now running " & resultsfile
WshShell.Run Chr(34) & ResultsFile & Chr(34),3,false    
End If
 
l.close
 
'##################
'FUNCTIONS
'##################
Function fctInput
l.writeline time & " - Input mode requested, no command-line parameters given."
    strComputer = InputBox("Enter name of computer to query " _
& "system stats from. " & vbcrlf & vbcrlf _
& "Click 'OK' without entering a " _
     & "computer name to pull server listing from: " _
     & vbcrlf & SourceFile & " " & vbcrlf & vbcrlf & "use '" _
& wscript.scriptname & " ?' for complete help.", "Query which computer?",strComputer)
strReadFromFile = "no"
    
    If IsNull(strComputer) Then 
        wscript.quit
    ElseIf strComputer = "" or strComputer = null Then 
        strReadFromFile = "yes"
        l.writeline time & " - No computer entered to query, defaulting to " & SourceFile
    End If
    'wscript.echo strReadFromFile
    'strComputer = Trim(strComputer)
    strOutput = InputBox("Would you like to: " & vbcrlf & vbcrlf _
     & "1 - send summary to email recipient(s) " & vbcrlf _
& "2 - open summary after execution", "Output method","1")
If strOutput = 1 Then strOutputdef = " - send summary to email recipient(s)"
If strOutput = 2 Then strOutputdef = " - open summary after execution"
 
'strReadFromFile = "no"
    If IsEmpty(strOutput) Then 
        wscript.quit
    End If
    l.writeline time & " - Output mode requested: " & strOutput & strOutputdef
    If strOutput > 0 and strOutput < 3 Then
     If strOutput = 1 Then
         strMailto = InputBox("Type in a valid email address " _
          & "to which you will send the output summary report." _
          & vbcrlf & vbcrlf & "Multiple recipients can be entered, " _
          & "but they must be separated by a semicolon (;).", "Enter recipient(s)" _
          & "on SMTP host " & strSMTPServer,strMailto)
        If strMailto = "" Then
         StrErr = "No email address provided. Defaulting to display mode."
         wscript.echo strErr
         blnSend = false
         blnSendSummary = false
        Else
         strErr = "Summary email will be sent to " & strMailto
         wscript.echo strErr
         blnSend = true
         blnSendMail = true
blnSendSummary = false
 
         If strReadfromfile = "yes" Then 
             blnSendMail = false
             blnSendSummary = true
         End If
        End If
     ElseIf strOutput = 2 Then 
         blnSend = false
         blnSendSummary = false
     End If            
     l.writeline strErr
 
    End If
 
End Function
 
'==Extract arguments from text file==
Function ReadTextFile
    i = 0
    
    If objargs.count = 0 Then Set objTextFile = objFSO.OpenTextFile(SourceFile, ForReading)
l.writeline time & " - Now reading from " & sourcefile
    Do While objTextFile.AtEndOfStream <> True
     If objTextFile.AtEndOfStream <> True Then
         strNextLine = objTextFile.Readline
        If Trim(strNextLine) <> "" Then objDictionary.Add i, Trim(strNextLine)
         i = i + 1
     End If    
    Loop
End Function
 
Function fctWarnings
On Error GoTo 0
 
If blnServices = true Then strWarnings = strWarnings & "<br><font size='1'><strong>" _
& "Services that need attention</strong></font><br>" & strService 
If blnDiskSpace = true Then strWarnings = strWarnings & "<br><font size='1'><strong>" _
& "Locally attached drives with less than " _
& intFreeSpaceThreshold & "% free <br></strong></font>" & strSpace 
If blnEvents = true Then strWarnings = strWarnings & "<br><font size='1'><strong>" _
& " Event log errors were detected </strong></font><br>Check the server log file for details <br>"
If blnAV = true Then strWarnings = strWarnings & "<br><font size='1'><strong>" _
& "Antivirus warning detected</strong></font><br>" & strAntiVirus
If blnOnline = false Then strWarnings = strWarnings & " <font size='1'><strong>" _
& "System did not respond to WMI queries or may be offline</strong></font>"
'wscript.echo "strWarnings: " & strWarnings    
strSpace = ""
strService= ""
strAntiVirus = ""
End Function
 
 
Function fctCopyFile(strSource,strDestFolder)
 
'wscript.echo strWarnings
Dim indexfile
    Set MyFile = fso.GetFile(strSource)
    'wscript.echo strDestFolder & strComputer & "_health.htm"
    MyFile.Copy (strDestFolder1 & "\" & strComputer & "_health.htm")
    'If blnSkipComputer = false Then 
    Call WriteMail
    
    'End If
 
End Function
 
Function WriteMail
If strWarnings <> "" Then 
    strWarningColor = "#FFCC99"
Else
    strWarningColor = "#DBFFED"
End If
strServerTable = strServerTable & vbcrlf & "<table cellspacing=0 border=0 width='100%'><tr style='cursor:pointer' onclick='showrows(tbl" & strComputer & ")' bgcolor='" & strWarningColor & "'><td width='20%'>" _
& "<strong><font face=" & strFontStyle & " size='2'><a href='" & resultsfile & "'>" & strComputer & "</a></strong></font></td><td><font size='1'>(" & strIPAddress & ")" _
& "</font></td></tr><tr><td colspan='100%'>" _
& "<table width='100%'><tr id='tbl" & strComputer & "'><td colspan='33%'><font face=" & strFontStyle & " size='1' color=" & strFontColor2 & ">" _
& strWarnings & "</font></td><td colspan='33%'><font face=" & strFontStyle & " size='1'>" & strBootTime & "</td>" _
& "<td colspan='33%'><font face=" & strFontStyle & " size='1' color=" & strFontColor2 & ">" _
& Now & "</font></td></tr></table></td></tr></table>"
 
strHideRows = strHideRows & "tbl" & strComputer & ".style.display = " & Chr(34) & "none" & Chr(34) & vbcrlf
 
End Function
 
Function WriteSummary
    Dim oldfile
    On Error GoTo 0 
    'Checks to see if the output file exists, then deletes it prior to making a new
    ' one (otherwise it would append to the end of the file).
 
 
    If ReportFileStatus(summaryfile) = "exists" Then
        l.writeline time & " - Deleting " & summaryfile
        Set oldfile = ws.GetFile(summaryfile)
        If intDebug = 1 Then wscript.echo summaryfile & " exists. Now deleting." 
        oldfile.Delete
        
     If CStr(err.number) <> 0 Then
         strErr = "You do not have sufficient permissions to delete " & oldfile & "."
         l.writeline strErr 
        If intDebug = 1 Then wscript.echo strErr
     End If
    
    End If
    'wscript.echo strDestFolder & "\summary.htm"
l.writeline time & " - Generating summary file: " & summaryfile    
'If intdebug = 0 Then wscript.echo summaryfile
    Set index = ws.OpenTextFile(summaryfile, ForAppending, True)
    If CStr(err.number) <> 0 Then 
        strMsg = "Error saving " & summaryfile & ". Be sure that this " _
          & "path exists." & vbcrlf & vbcrlf & "Actual error was - " & err.description
         l.writeline strMsg
         wscript.echo strMsg
         wscript.quit
    End If
    'Set indexfile = objFSO.CreateTextFile( & Chr(34), True)
    l.writeline time & " - Writing summary information for " & strComputer & " to " & summaryfile
    'wscript.echo strServerTable
    index.writeline strServerTable & "<table width='100%'><tr bgcolor='black'><td colspan='100%'><font face=" & strFontStyle & " color='white' size='1'>" _
     & "Finished server indexing at " & Now & "</font></td></tr></table>"
    index.writeline "<script language=" & Chr(34) & "VBSCRIPT" & Chr(34) & ">" 
    index.writeline strHideRows
    index.writeline "Function ShowRows(strRow)" & vbcrlf
    index.writeline "if strRow.style.display = " & Chr(34) & "inline" & Chr(34) & " then" & vbcrlf
    index.writeline " strRow.style.display = " & Chr(34) & "none" & Chr(34) & vbcrlf
    index.writeline "else" & vbcrlf
    index.writeline " strRow.style.display = " & Chr(34) & "inline" & Chr(34) & vbclrf
    index.writeline "end if" & vbcrlf
    index.writeline "End Function" & vbcrlf
    index.writeline "</script></body></html>"
    index.close
End Function
 
'####Main function for running server checks####
Function checks (strComp)
 
'==Run the check subroutines/functions==
 
chkopsys(strComp) 'Func
'wscript.echo "blnSkipComputer = " & blnSkipComputer
If blnSkipComputer = False Then 
chkComputer(strComp) 'Func
chkdiskspace (strComp) 'Sub
l.writeline time & " - Checking AV details."
On Error Resume Next
If intAV = 0 Then 
    l.writeline time & " - McAfee VirusScan was specified (IntAV = " & intAV & ")."
 
    begintable("McAfee Anti-Virus")
     chkav "Product Name:","Software\Network Associates\TVD\VirusScan Enterprise\CurrentVersion","Product", "string" 'Sub
     chkav "Product Version:","Software\Network Associates\TVD\VirusScan Enterprise\CurrentVersion","szProductVer", "string" 
     chkav "Virus Definition:","Software\Network Associates\TVD\VirusScan Enterprise\CurrentVersion","szVirDefVer", "string"
     chkav "Virus Definition Date:","Software\Network Associates\TVD\VirusScan Enterprise\CurrentVersion","szVirDefDate", "string"
     chkav "Product Engine:","Software\Network Associates\TVD\VirusScan Enterprise\CurrentVersion","szEngineVer", "string"
    endtable
ElseIf intAV = 1 Then 
    l.writeline time & " - Norton Antivirus was specified (IntAV = " & intAV & ")."
begintable("Norton Antivirus")
chkav "NAV Definition Version:","Program Files\Symantec AntiVirus","DEFWATCH_10"
chkav "Product Version:","Program Files\Symantec AntiVirus","szProductVer", "string"
 chkav "Virus Definition Date:","Program Files\Symantec AntiVirus","szVirDefDate", "string"
endtable 
ElseIf intAV = 2 Then 
    l.writeline Time & " - Trend OfficeScan was specified (IntAV = " & intAV & ")."
    begintable("Trend OfficeScan")
        chkav "Product Version:","SOFTWARE\TrendMicro\PCCillinNTCorp\CurrentVersion\Misc.","ProgramVer", "string"
        chkav "Internal Pattern Version:","SOFTWARE\TrendMicro\PCCillinNTCorp\CurrentVersion\Misc.","InternalPatternVer", "dword"
        chkav "Pattern Date:","SOFTWARE\TrendMicro\PCCillinNTCorp\CurrentVersion\Misc.","PatternDate", "string"
    endtable
    
End If
 
    chkservices(strComp) 'Func
    chkevents (strComp) 'Func
 
    Set w = ws.OpenTextFile(resultsfile, ForReading, False, TristateUseDefault)
    strMessage = w.ReadAll
    'MsgBox strMessage
    w.close
Else
 
End If
    
 
res.Writeline ("</html>")
res.close
 
'==End Function==
End Function
 
'####Check OS Version and Free Physical Memory####
Function chkopsys (strComp)
If intDebug = 0 Then On Error Resume Next
l.writeline time & " - Checking OS details."
If dbgTitle <> "" Then objdiv.innerhtml = strMsg & "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "Checking Operating System...</font><br>"
 
'wscript.echo StrComp
'==Connect to winmgmts==
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComp & "\root\cimv2")
 
Call fctErrorHandling
 
Set colopsys = objWMIService.ExecQuery _
("Select Caption, CSDVersion, FreePhysicalMemory from Win32_OperatingSystem")
 
'==Write header to htm file==
res.Writeline ("<table bgcolor=" & strHDRColor2 & " BORDER=1 width=100% cellspacing=0 cellpadding=3>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor1 & " colspan=6 width=400>")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=" & strFontStyle & " size=2 color=" & strFontColor2 & ">Operating System information</font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=59><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Operating System</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=59><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Last Booted</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Service Pack</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Free Memory</font></th>")
res.Writeline ("</tr>")
'endtable
 
'==Write results to htm file==
For each objopsys in colopsys
res.Writeline ("<TR>" & strbeginline & objopsys.Caption & strMiddleLine & GetBootTime(StrComp) & strEndLine)
res.Writeline (strbeginline & objopsys.CSDVersion & strEndline)
res.Writeline (strbeginline & round(objopsys.FreePhysicalMemory/1000,2) & "Mb" & strEndLine & "</TR>")
Next
 
    Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    For Each objAdapter in colAdapters
        If Not IsNull(objAdapter.IPAddress) Then
         For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
            'Wscript.Echo "IP address: " & objAdapter.IPAddress(i)
            strIPAddress = objAdapter.IPAddress(i) & ";" & strIPAddress 
         Next
 
        End If
    Next
'round(objItem.FreeSpace/1000000000,2)
'==End Function==
End Function
 
'####Check OS Version and Free Physical Memory####
Function chkComputer (strComp)
If dbgTitle <> "" Then objdiv.innerhtml = strMsg & "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "Checking computer hardware ...</font><br>"
'==Connect to winmgmts==
l.writeline time & " - Checking computer hardware details."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComp & "\root\cimv2")
 
Set colCompItems = objWMIService.ExecQuery _
("Select Manufacturer, Model, Username from Win32_ComputerSystem")
 
'==Write header to htm file==
res.Writeline ("<table BORDER=1 width=100% cellspacing=0 cellpadding=3>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor1 & " colspan=6 width=400>")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=" & strFontStyle & " size=2 color=" & strFontColor2 & ">Computer Hardware information</font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=59><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Manufacturer</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Model</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Logged on User</font></th>")
res.Writeline ("</tr>")
 
'==Write results to htm file==
For each objItem in ColCompItems
res.Writeline ("<TR>" & strbeginline & objItem.Manufacturer & strEndLine)
res.Writeline (strbeginline & objItem.Model & strEndline)
res.Writeline (strbeginline & objItem.Username & strEndLine & "</TR>")
Next
 
'==End Function==
End Function
 
 
'####Check started and stopped services####
Function chkservices (strComp)
If dbgTitle <> "" Then objdiv.innerhtml = strMsg & "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "Checking automatic services...</font><br>"
l.writeline time & " - Checking services."
'==Connect to winmgmts==
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComp & "\root\cimv2")
 
 
'==Run query to get all services with Auto start==
Set colsvc = objWMIService.ExecQuery _
("Select DisplayName, StartMode, StartName, State from Win32_Service Where StartMode = 'Auto'")
 
'==Write heard to htm file==
res.Writeline ("<table border=1 width=100% cellspacing=0 cellpadding=3>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor1 & " colspan=6 width=400>")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=" & strFontStyle & " size=2 color=" & strFontColor2 & ">Services alerts</font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=59><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Service Name</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=59><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Logon Account</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=59><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Startup Method</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=59><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Current State</font></th>")
res.Writeline ("</tr>")
 
'==Write results to htm file==
For each objsvc in colsvc
On Error GoTo 0
'wscript.echo objsvc.startname
 
Call bgcolor
If InStr(objsvc.StartName,strCheckAccount) and strCheckAccount <> "" Then
'wscript.echo objsvc.startname
res.Writeline ("<TR bgcolor='" & strbgcolor & "'>" & strBeginLine & objsvc.DisplayName & strMiddleLine _
& "<font face=" & strFontStyle & " color='red' size='1'>" & objsvc.StartName & "</font>" _
& strMiddleLine & objsvc.StartMode & "</td><td>" _
& "<font face=" & strFontStyle & " color='red' size='1'>" & objsvc.State & strEndLine)
strService = strService & objsvc.DisplayName & " is running via credentials: <strong>" & objsvc.StartName & "</strong><br>"     
End If
 
Call bgcolor 
If LCase(objsvc.State) = "stopped" Then
 
serviceerr = "failed"
res.Writeline ("<TR bgcolor='" & strbgcolor & "'>" & strBeginLine & objsvc.DisplayName & strMiddleLine _
& objsvc.StartName & strMiddleLine & objsvc.StartMode & "</td><td>" _
& "<font face=" & strFontStyle & " color='red' size='1'>" & objsvc.State & strEndLine)
strService = strService & objsvc.DisplayName & " is currently " & objsvc.State & "<br>"
Else
End If
Next
 
 
 
If serviceerr = "failed" then
blnErrors = true
blnServices = true
Else
res.Writeline ("<TR>"& strbeginline & "No services are in alarm status" & strendline)
End If
res.Writeline ("</table>")
 
'==End Function==
End Function
 
 
'*****************************************************************
'* Get boot up time of the server
'*****************************************************************
Function GetBootTime(StrComp)
 
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
 
Set objWMIService = GetObject("winmgmts:\\" & StrComp & "\root\CIMV2")
Set colOperatingSystems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
On Error Resume Next
'If CStr(err.number) <> "" Then Call fcterrorhandling
    
For Each objOS in colOperatingSystems 
        dtmBootup = objOS.LastBootUpTime 
        Dim dtmTimeUp
        
        'wscript.echo dtmBootup
        
        dtmLastBootupTime = WMIDateStringToDate(dtmBootup) 
 
        dtmSystemUpTime = DateDiff("h", dtmLastBootUpTime, Now)
        
        If dtmSystemUptime > 24 Then 
            dtmTimeUp = DateDiff("d",dtmLastBootUpTime, Now) & " day(s)" 
        Else
            dtmTimeUp = dtmSystemUptime & " hour(s)"
        End If
 
        strBootTime = dtmLastBootupTime & " (" & dtmTimeUp & " ago)"
        GetBootTime = strBootTime
 
        'dtmSystemUptimeHours 
        'Wscript.Echo "Last booted: " & dtmLastBootupTime & " (" & dtmSystemUptime & " hours)"
Next 
End Function
 
 
'####Check status of backups (To be writte)####
Function chkbackups ()
 
'==End Function==
End Function
 
'####Check event logs for warnings and errors####
Function chkevents (strComp)
On Error Resume Next
l.writeline time & " - Checking the " & strEventCount & " last occurences of events during the last " & IntDaysBack & " days."
Const CONVERT_TO_LOCAL_TIME = True
On Error GoTo 0
If dbgTitle <> "" Then objdiv.innerhtml = strMsg & "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "Checking the " & strEventCount & " most recent entries occuring during the last " & IntDaysBack & " day(s) of event logs...</font><br>"
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = Date
dtmStartDate.SetVarDate DateToCheck - IntDaysBack, CONVERT_TO_LOCAL_TIME 
dtmEndDate.SetVarDate DateToCheck + IntDaysBack, CONVERT_TO_LOCAL_TIME
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Security)}!\\" & StrComp & "\root\cimv2")
 
Set colEvents = objWMIService.ExecQuery _
("Select ComputerName, EventCode, Logfile, SourceName, TimeWritten, Type, Message from Win32_NTLogEvent Where " _
& "TimeWritten >= '" _ 
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "' and Type = 'error' or TimeWritten >= '" _ 
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "' and Type = 'warning' and Type = 'failure'") 
 
'==Run query to get errors and warnings==
'Set colLoggedEvents = objWMIService.ExecQuery _
' ("Select ComputerName, EventCode, SourceName, TimeGenerated, Type, Message from Win32_NTLogEvent where Type = 'error' or Type = 'warning'")
 
'==Write header to htm file==
res.Writeline ("<table border=1 width=100% cellspacing=0 cellpadding=3>")
res.Writeline ("<tr colspan='100%'>")
res.Writeline ("<th bgcolor=" & strHDRColor1 & " colspan='100%'>")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=" & strFontStyle & " size=2 color=" & strFontColor2 & ">Last " & strEventCount & " events occurring within the previous " & IntDaysBack & " day(s)</font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<td bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Computer Name</font></td>")
res.Writeline ("<td bgcolor=" & strHDRColor2 & " width=200><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Logfile</font></td>")
res.Writeline ("<td bgcolor=" & strHDRColor2 & " width=200><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Event Code/Log</font></td>")
res.Writeline ("<td bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Source Name</font></td>")
res.Writeline ("<td bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Time Written</font></td>")
res.Writeline ("<td bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Type</font></td>")
res.Writeline ("<td bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Message</font></td>")
res.Writeline ("</tr>")
 
'==Write results to htm file==
 
Dim strEventCount1
strEventCount1 = -1
 
For Each objEvent in colEvents
 
Call bgcolor
On Error GoTo 0
 
res.Writeline ("<TR bgcolor='" & strbgcolor & "'>")
'res.Writeline (strbeginline & objEvent.Category & strendline)
res.Writeline (strbeginline & objEvent.ComputerName & strendline)
res.Writeline (strbeginline & objEvent.logfile & strendline)
 
res.Writeline (strbeginline & "<a href='http://www.google.com/search?hl=en&q=%22event%22+%22" _
& objEvent.EventCode & "%22+%22ID%22+%22windows%22+%22" & objEvent.SourceName & "%22' target='_blank'>" & objEvent.EventCode & "</a>" & strendline)
 
res.Writeline (strbeginline & objEvent.SourceName & strendline)
res.Writeline (strbeginline & WMIDateStringToDate(objEvent.TimeWritten) & strendline)
strEventCount1 = strEventCount1 + 1
 
If LCase(objEvent.Type) = "error" Then
 
    res.Writeline ("<TD><font face=" & strFontStyle & " color='red' size=1>" & objEvent.Type & strendline)
    blnErrors = true
    blnEvents = true
 
Else
    res.Writeline (strbeginline & objEvent.Type & strendline)
End If
res.Writeline (strbeginline & objEvent.Message & strendline)
res.Writeline ("</TR>")
 
If strEventCount1 > strEventCount Then 
    'wscript.echo "Count is " & strEventCount1
Exit For
End If
Next
res.Writeline ("<tr><td colspan='100%' bgcolor='black'><font color='white' size='1'>Health check finished at: " & Now & "</font>" & strendline)
 
'==End Function==
End Function
 
Function BGColor
    If Count = 0 or IntCopyCount = 0 Then    
        strbgcolor = bgcolor0
        Count = 1
        IntCopyCount = 1
    ElseIf Count = 1 or IntCopyCount = 1 Then
        strbgcolor = bgcolor1
        Count = 0
        IntCopyCount = 0
    End If
End Function
 
Function fctErrorHandling
If cstr(err.number) <> 0 then
    'wscript.echo err.number & " - " & err.description
    l.writeline Time & " - Error: " & err.number & " " & err.description 
    blnOnline = false
    blnSkipComputer = true
 
    Exit Function
End If
End Function
 
 
'------------------
'Function EmailFile - email the warning file
'------------------
Function SendMail(strFrom,strTo,strSubject,strMessage)
Dim iMsg, iConf, Flds
 
l.writeline time & " - Calling sendmail routine"
l.writeline time & " - To: " & strMailto
l.writeline time & " - From: " & strMailFrom
l.writeline time & " - Subject: " & strSubject
l.writeline time & " - SMTP Server: " & strSMTPServer
 
If dbgTitle <> "" Then objdiv.innerhtml = "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "sending mail to " & strMailTo & "...</font><br>"
 
'// Create the CDO connections.
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
 
 
'// SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
 
'// Set the SMTP server address here.
.Item(cdoSMTPServer) = strSMTPServer
.Update
End With
 
'// Set the message properties.
With iMsg
Set .Configuration = iConf
.To = strMailTo
.From = strMailFrom
.Subject = strSubject
'.TextBody = strMessage
End With
 
 
iMsg.HTMLBody = strMessage
 
 
'// Send the message.
On Error Resume Next 
iMsg.Send ' send the message.
If CStr(err.number) <> 0 Then
    l.writeline Time & " - Problem sending mail to " & strSMTPServer & "."
    l.writeline Time & " - Error: " & err.description
Else
    l.writeline Time & " - Connected successfully to " & strSMTPServer
End If
End Function
 
'###################
' SUBROUTINES
'###################
 
'####Check disk space subroutine####
Sub chkdiskspace (strComp)
 
If dbgTitle <> "" Then objdiv.innerhtml = strMsg & "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "Checking disk space...</font><br>"
l.writeline time & " - Checking disk space."
'==Connect to winmgmts==
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComp & "\root\cimv2")
 
 
'==Run query to identify logical disks==
Set colDisks = objWMIService.ExecQuery _
("Select Freespace, Name, Size from Win32_LogicalDisk where DriveType = 3")
Call fctErrorHandling
 
'==Write header to htm file==
res.Writeline ("<table border=1 width=100% cellspacing=0 cellpadding=3>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor1 & " colspan=6 width=200>")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=" & strFontStyle & " size=2 color=" & strFontColor2 & ">Disk space</font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Disk ID</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Percentage Free Space</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Free Space</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Total Space</font></th>")
res.Writeline ("</tr>")
 
'==Write results to htm file==
For each objDisk in colDisks
Call bgcolor
res.Writeline ("<TR bgcolor='" & strbgcolor & "'><TD><font face=" & strFontStyle & " color=" & strFontColor2 & " size=1> " & objDisk.Name & strendline)
 
If (objDisk.Freespace/objDisk.Size)*100 <=10 Then
 
fontcol = "#FF0000"
Else
fontcol = "#666666"
End If
If objDisk.Freespace > 10000 Then
    strUnit = "GB"
    strDiskSize = FormatNumber(objDisk.Freespace / 1073741824,2)
    strDiskTotal = FormatNumber(objDisk.Size / 1073741824,2)
ElseIf objDisk.Freespace < 1 Then
    strUnit = "KB"
    strDiskSize = FormatNumber(objDisk.Freespace / 1024,2)
    strDiskTotal = FormatNumber(objDisk.Size / 1024,2)
ElseIf objDisk.Freespace < 1000 Then
    strUnit = "MB"
    strDiskSize = FormatNumber(objDisk.Freespace/1048576,2)
    strDiskTotal = FormatNumber(objDisk.Size / 1048576,2)
End If
strPercentFree = round((objDisk.Freespace/objDisk.Size)*100,2)
 
If strPercentFree < intFreeSpaceThreshold then
'wscript.echo strPercentFree
strSpace = strSpace & objDisk.Name & " - " & round((objDisk.Freespace/objDisk.Size)*100,2) _
& "% free (" & FormatNumber(objDisk.Freespace / 1073741824,2) & "Gb remaining)<br>"
    res.Writeline ("<TD><font face=" & strFontStyle & " color='red' size=1>" & strPercentFree & "%" & strendline)
    blnErrors = true
    blnDiskSpace = true
Else
    res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strPercentFree & "%" & strendline)
End If
 
res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strDiskSize & strUnit & strendline)
res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strDiskTotal & strUnit & strendline & "</TR>")
 
Next
 
'==End Subroutine==
End sub
 
'####Check for AV definition files####
Function chkav (strDescription, strKeyPath, strValueName, strRegType)
On Error Resume Next
 
'wscript.echo strValueName
 
If dbgTitle <> "" Then objdiv.innerhtml = strMsg & "<font face=" & strFontStyle & " color=" & strFontColor2 & ">" _
& "Checking AV status...</font><br>"
 
'==Connect to winmgmts==
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
 
 
'==Get definition version from registry==
If strRegType = "dword" Then 
    oReg.GetDWordValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
ElseIf strRegType = "string" Then 
    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
End If
 
'wscript.echo strValue
 
If strValueName = "szVirDefDate" or strValueName = "PatternDate" Then
    If strValueName = "PatternDate" Then 
        
        defRest = Right(strValue,4)
        strValue = Left(defRest,2) & "/" & Right(defRest,2) & "/" & Left(strValue,4)
 
    End If
    strDiff = Date - CDate(strValue)
    If strDiff > intVirusDefAge Then 
        strAntivirus = "AV definitions last updated: " & CDate(strValue) _
         & " - Virus definitions appear to be " _
          & "more than " & intVirusDefAge & " days old."
        strTempColor = "'red'"
        blnAV = true
    Else
        strTempColor = strFontColor2
        blnAV = false
    End If             
    
    res.Writeline ("<TR><TD><font face=" & strFontStyle & " color=" & strFontColor2 & " size=1> " & strDescription _
     & "</td><td><font face=" & strFontStyle & " color=" & strTempColor & " size=1> " & strValue & "</font></TD></TR>")
 
ElseIf strValueName <> "" Then 
    res.Writeline ("<TR><TD><font face=" & strFontStyle & " color=" & strFontColor2 & " size=1> " & strDescription _
     & "</td><td><font face=" & strFontStyle & " color=" & strFontColor2 & " size=1> " & strValue & "</font></TD></TR>")
 
End If
 
On Error Resume Next
If strValue = "DEFWATCH_10" Then 
strAntiVirus = "The defined virus software may not be installed on this computer."
blnAV = true
Else
'wscript.echo "no av..."
 
strValue = "n/a"
End If
'wscript.quit
 
'==Write results to htm file==
 
 
 
'==End subroutine==
End Function
'~~[/script]~~
 
Sub BeginTable(strTableHeader)
    res.Writeline ("<table border=1 width=100% cellspacing=0 cellpadding=3>")
    res.Writeline ("<tr>")
    res.Writeline ("<th bgcolor=" & strHDRColor1 & " colspan=6 width=400>")
    res.Writeline ("<p align=left>")
    res.Writeline ("<b><font face=" & strFontStyle & " size=2 color=" & strFontColor2 & ">" & strTableHeader & "</font></b></p>")
    res.Writeline ("</th>")
    res.Writeline ("</tr>")
End Sub
 
Sub EndTable
    res.Writeline ("</table>")
End Sub
 
Function WMIDateStringToDate(dtmDate) 
'wscript.echo dtmBootup
'Thanks to Piers Dickinson!
    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    If CStr(err.number) <> "0" Then Call fcterrorhandler
    
End Function 
 
' The MakeSureDirectoryTreeExists Function
 
' Although the FSO model doesn't have a direct method to create nested
' folders, you can use the following function. This VBScript function uses
' VBScript's Split function to break the folder path it receives into
' components. From those components, the MakeSureDirectoryTreeExists
' creates subfolders, one at a time. Because the function checks for the
' folder's existence before proceeding, you can pass it any tree, as long as
' you make sure that, after it returns, the entire tree exists as you specified.
' With the MakeSureDirectoryTreeExists function, a call such as
 
'    MakeSureDirectoryTreeExists "C:\one\two\three"
 
' is legitimate and won't result in an error message.
 
' The MakeSureDirectoryTreeExists Function
 
' Although the FSO model doesn't have a direct method to create nested
' folders, you can use the following function. This VBScript function uses
' VBScript's Split function to break the folder path it receives into
' components. From those components, the MakeSureDirectoryTreeExists
' creates subfolders, one at a time. Because the function checks for the
' folder's existence before proceeding, you can pass it any tree, as long as
' you make sure that, after it returns, the entire tree exists as you specified.
' With the MakeSureDirectoryTreeExists function, a call such as
 
'    MakeSureDirectoryTreeExists "C:\one\two\three"
 
' is legitimate and won't result in an error message.
 
Function MakeSureDirectoryTreeExists(dirName)
Dim aFolders, newFolder
    dim delim
    ' Creates the FSO object.
    Set fso = CreateObject("Scripting.FileSystemObject")
 
    ' Checks the folder's existence.
    If Not fso.FolderExists(dirName) Then
 
        ' Splits the various components of the folder name.
        If instr(dirname,"\\") then
         delim = "-_-_-_-"
            dirname = replace(dirname,"\\",delim)
            'wscript.echo dirname
        End if
 
        aFolders = split(dirName, "\")
 
        If InStr(dirname,delim) Then
            dirname = replace(aFolders(0),delim,"\\")
            'wscript.echo "aFolders = " & dirname
        End if
 
        ' Obtains the drive's root folder.
        
        newFolder = fso.BuildPath(dirname, "\")
    
        ' Scans each component in the array, and create the appropriate folder.
        For i=1 to UBound(aFolders)
            If IntDebug = 1 Then 
                strTempVar = "Checking to see if " & newfolder _
                  & " exists..."
                Call writedebug(strtempvar)
            End If
            newFolder = fso.BuildPath(newFolder, aFolders(i))
            'wscript.echo newfolder
            
            
            If Not fso.FolderExists(newFolder) Then
                If IntDebug = 1 Then 
                    strTempVar = "Creating " & newfolder
                    Call writedebug(strTempVar)
                End If
                fso.CreateFolder newFolder
                err.clear
            End If
        Next
    End If
End Function
 
'-----------------
'Function IE Status
'-----------------
Function IEStatus
 
'added by Rob - IE status indicator code
If blnProgressMode = true Then
    If blnDebugMode Then
        dbgTitle = "Server Health Check"
    Else
        dbgTitle = "Server Health Check"
    End If    
    dbgToolBar = False
    dbgStatusBar = False
    If blnDebugMode Then
        dbgResizable = True
    Else
        dbgResizable = False
    End If
    dbgWidth = 500
    dbgHeight = 320
    dbgLeft = 0
    dbgTop = 0
    dbgVisible = True
    dlgBarWidth = 380
    dlgBarHeight = 23 
    dlgBarTop = 80
    dlgBarLeft = 50
    dlgProgBarWidth = 0
    dlgProgBarHeight = 18 
    dlgProgBarTop = 82
    dlgProgBarLeft = 50
    dlgBar = "left: " & dlgBarLeft & "; top: " & dlgBarTop & "; width: " & dlgBarWidth _
     & "; height: " & dlgBarHeight & ";"
    dlgProgBar = "left: " & dlgProgBarLeft & "; top: " & dlgProgBarTop & "; width: " _
     & dlgProgBarWidth & "; height: " & dlgProgBarHeight & ";"
    wdBar = 1 * dlgBarWidth
End If
 
If blnProgressMode = true Then
    Set IE = CreateObject("InternetExplorer.Application")
    'strScriptVer = "version would go here"
 
    strTempFile = WshSysEnv("TEMP") & "\progress.htm"
    ws.CreateTextFile (strTempFile)
Set f1 = ws.GetFile(strTempFile)
Set ts = f1.OpenAsTextStream(2, True)
ts.WriteLine("<!-- saved from url=(0014)about:internet -->")
ts.WriteLine("<html><head><title>" & dbgTitle & " " & strScriptVer & " </title>")
ts.WriteLine("<style>.errortext {color:red}")
    ts.WriteLine(".hightext {color:blue}</style>")
    ts.WriteLine("</head>")
    ts.WriteLine(strHDRCode & " <br><strong><font size='2' color='" & fcolor & "' face='" & fstyle & "'>" _
         & "  Querying <font color'=" & fcolor & ">" & strComputer & "...</font></strong><br>" _
         & "   <br>")
    ts.WriteLine("<center><table width='100%' bgcolor='" & bgcolor1 & "'><tr><td>")
    If blnDebugMode Then
        ts.WriteLine("<body bgcolor ='" & stsBGColor & "' scroll='yes' topmargin='0' leftmargin='0'"_
        & " style='font-family: " & fstyle & "; font-size: 0.6em color: #000000;"_
        & " font-weight: bold; text-align: left'><center><font face=" & fstyle & ">"_
        & " <font size='0.8em'> <hr color='blue'>")
    Else
        ts.WriteLine("<body bgcolor = '" & stsBGColor & "' scroll='no' topmargin='0' leftmargin='0' "_
        & " style='font-family: " & fstyle & "; font-size: 0.6em color: #000000;"_
        & " font-weight: bold; text-align: left'><center><font face=" & fstyle & ">"_
        & " <font size='0.8em'> <hr color='blue'>")
    End If
    ts.WriteLine("<div id='ProgObject' align='left'align='left' style='width: 450px;height: 140px;overflow:scroll'></div><hr color='blue'>")            
    If blnDebugMode Then
        ts.WriteLine("<div id='ProgDebug' align='left'></div>")
    End If
 
    ts.WriteLine("<script LANGUAGE='JavaScript1.2'>")
    ts.WriteLine("<!-- Begin")
    ts.WriteLine("function initArray() {")
    ts.WriteLine("this.length = initArray.arguments.length;")
    ts.WriteLine("for (var i = 0; i < this.length; i++) {")
    ts.WriteLine("this[i] = initArray.arguments[i];")
    ts.WriteLine(" }")
    ts.WriteLine("}")
    ts.WriteLine("var ctext = ' ';")
    ts.WriteLine("var speed = 1000;")
    ts.WriteLine("var x = 0;")
    ts.WriteLine("var color = new initArray(")
    ts.WriteLine("'red',")
    ts.WriteLine("'blue'")
    ts.WriteLine(");")
    ts.WriteLine("document.write('<div id=" & Chr(34) & "ProgFlash" & Chr(34) & ">"_
     & "<center>'+ctext+'</center></div>');")
    ts.WriteLine("function chcolor(){")
    ts.WriteLine("document.all.ProgFlash.style.color = color[x];")
    ts.WriteLine("(x < color.length-1) ? x++ : x = 0;")
    ts.WriteLine("}")
    ts.WriteLine("setInterval('chcolor()',1000);")
    ts.WriteLine("// End -->")
    ts.WriteLine("</script>")
    ts.WriteLine("<div id='ProgBarId' align='left'></div>")
    ts.WriteLine("</font></center>")
    ts.WriteLine("</tr></td>")
    ts.WriteLine("</table></center>")
    ts.WriteLine("</body></html>")
    ts.Close
    fctSetupIE(strTempFile)
    Set objDIV = IE.Document.All("ProgObject")
    If blnDebugMode Then
        Set objDBG = IE.Document.All("ProgDebug")
    End If
    Set objFlash = IE.Document.All("ProgFlash")
    Set objPBar = IE.Document.All("ProgBarId")
    Set objBar = IE.Document
End If
End Function
 
'*******************************************************************
'*    Name:    fctSetupIE
'*    Function:    Setup an IE windows of 540 x 200 to display 
'*     progress information.
'*******************************************************************
Sub fctSetupIE(File2Load)
    IE.Navigate File2Load
    IE.ToolBar = dbgToolBar
    IE.StatusBar = dbgStatusBar
    IE.Resizable = dbgResizable
    Do
    Loop While IE.Busy
    IE.Width = dbgWidth
    IE.Height = dbgHeight
    IE.Left = dbgLeft
    IE.Top = dbgTop
    IE.Visible = dbgVisible
    wshshell.AppActivate("Microsoft Internet Explorer")
End Sub
 
'===================
'Function to see if outputfile already exists
'===================
 
Function ReportFileStatus(filespec)
 
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = "exists"
Else
msg = "does not exist"
End If
 
ReportFileStatus = msg
If IntDebug = 1 Then wscript.echo filespec & " " & msg
 
End Function

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, you've got this part for the NAV stuff:

ElseIf intAV = 1 Then
    l.writeline time & " - Norton Antivirus was specified (IntAV = " & intAV & ")."
begintable("Norton Antivirus")
chkav "NAV Definition Version:","Program Files\Symantec AntiVirus","DEFWATCH_10"
chkav "Product Version:","Program Files\Symantec AntiVirus","szProductVer", "string"
 chkav "Virus Definition Date:","Program Files\Symantec AntiVirus","szVirDefDate", "string"
EndTable

but the chkav function looks at registry paths in HKEY_LOCAL_MACHINE.

You can see McAfree, for example, looks at "HKLM\Software\Network Associates\TVD\VirusScan Enterprise\CurrentVersion" for the virus definition.

Does McAfee have a similar registry entry that tells you this?

Regards,

Rob.
Avatar of cgooden01

ASKER

I will check on this in the morning and follow up with you.  Thanks!
Still can not get this to grab Symantec Norton data.  I have other scripts that run with no problems, but this one work so well with the exception of retrieving the version and latest dat file.  Any suggestions
Made several modifications and still to no avail.  This script is perfect for server documentation.  Just missing the Product Version and lasted Virus Dat File.  
What registry paths do you have for Norton?  I assume they'll be in HKEY_LOCAL_MACHINE\Software/Symantec/Norton Antivirus
Or
HKEY_LOCAL_MACHINE\Software\Symantec\SharedDefs
 or something like that....

Is there anything there that might show the version or date?

Regards,

Rob.
Have tried several versions of adding Registry settings and local files that would permit this entry of data.  Any suggestions

ElseIf intAV = 1 Then
    l.writeline time & " - Norton Antivirus was specified (IntAV = " & intAV & ")."
begintable("Norton Antivirus")
chkav "NAV Definition Version:","Program Files\Common Files\Symantec Shared\VirusDefs","DEFWATCH_10"
chkav "Product Version:","Program Files\Common Files\Symantec Shared\VirusDefs","string"
 chkav "Virus Definition Date:","Program Files\Common Files\Symantec Shared\VirusDefs","string"
endtable
Tried this way but still to no avail.

ElseIf intAV = 1 Then
    l.writeline time & " - Norton Antivirus was specified (IntAV = " & intAV & ")."
begintable("Norton Antivirus")
chkav "NAV Definition Version:","HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\Common Client","Version","string"
chkav "Product Version:","HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\SharedDefs\DefWatch","DEFWATCH_10","string"
 chkav "Virus Definition Date:","HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\SharedDefs\DefWatch","string"
endtable
ASKER CERTIFIED SOLUTION
Avatar of cgooden01
cgooden01
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent! Well done.  I'm sorry I don't have any Norton installations so I couldn't pinpoint the right registry keys, but I knew it had to be there somewhere...

Rob.