[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Windows update check monitor added to the Shire



This is *not* fully regression tested (it works for me); but, here is the code using a disconnected record set for sorting. Also, IE8 does not format the table the same way Firefox 3 does, and I gave up trying to make it do it. So, you will likely want to adjust the styles to fit your needs.

Ray

'Change these to match your environment
Const AlarmRedLevel = 10
Const AlarmYellowLevel = 5
Const AlarmRed = "red"
Const AlarmYellow = "yellow"
Const AlarmGreen = "green"
Const adVarChar = 200
Const adInteger = 3
Const MaxCharacters = 255
Const adFldIsNullable = 32


Dim oSearcher, oResults, oUpdates, oShell, oRS
Set oSearcher = CreateObject("Microsoft.Update.Searcher")
Set oResults = oSearcher.Search("Type='Software'")
Set oUpdates = oResults.Updates
Set oShell = WScript.CreateObject("WScript.Shell")
Set oRS = CreateObject("ADOR.Recordset")

oRS.Fields.Append "title", adVarChar, MaxCharacters
oRS.Fields.Append "severity", adVarChar, MaxCharacters, adFldIsNullable
'I do not know how large the actual description field is; it will bomb during updates if the description is not large enough
oRS.Fields.Append "description", adVarChar, MaxCharacters + MaxCharacters
oRS.Fields.Append "size", adInteger
oRS.Fields.Append "deadline", adVarChar, MaxCharacters, adFldIsNullable
oRS.Fields.Append "url", adVarChar, MaxCharacters
oRS.Fields.Append "kbs", adVarChar, MaxCharacters

Dim strOut, IsInstalled, strKBs, strURL, IsEven, iUpdates, iUpdatesNeeded, strClass, strAlarm, strSvrName, strSeverity
iUpdates = oUpdates.Count
strSvrName = LCase(oShell.ExpandEnvironmentStrings("%COMPUTERNAME%"))

iUpdatesNeeded = 0
oRS.Open
For i = 0 to iUpdates - 1
                IsInstalled = oUpdates.Item(i).IsInstalled
                If (IsInstalled = False) Then
                                strKBs = ""
                                iUpdatesNeeded = iUpdatesNeeded + 1
                                oRS.AddNew
                                oRS("title") = oUpdates.Item(i).Title
                                strSeverity = oUpdates.Item(i).MsrcSeverity
                                If (IsNull(strSeverity) = True) Then
                                                strSeverity = "9 - none"
                                Else
                                                If (IsEmpty(strSeverity) = True) Then
                                                                strSeverity = "9 - none"
                                                Else
                                                                Select Case UCase(strSeverity)
                                                                                Case "CRITICAL"
                                                                                                strSeverity = "1-Critical"
                                                                                Case "IMPORTANT"
                                                                                                strSeverity = "2-Important"
                                                                                Case "MODERATE"
                                                                                                strSeverity = "3-Moderate"
                                                                                Case "LOW"
                                                                                                strSeverity = "4-Low"
                                                                                Case Else
                                                                                                strSeverity = "9-" & strSeverity
                                                                End Select
                                                End If 'severity empty
                                End If 'severity null
                                oRS("severity") = strSeverity
                                oRS("description") = oUpdates.Item(i).Description
                                oRS("size") = oUpdates.Item(i).MaxDownloadSize
                                oRS("deadline") = oUpdates.Item(i).Deadline
                                oRS("url") = oUpdates.Item(i).SupportURL
                                For Each strArticle in oUpdates.Item(i).KBArticleIDs
                                                If (Len(strKBs) > 0) Then
                                                                strKBs = strKBs & ", " & strArticle
                                                Else
                                                                strKBs = strArticle
                                                End If
                                Next 'each kb
                                oRS("kbs") = strKBs
                                oRS.Update
                End If
Next
oRS.Sort = "severity ASC, title ASC"
oRS.MoveFirst

If (iUpdatesNeeded > AlarmRedLevel) Then
                strAlarm = AlarmRed & " " & Date & " " & LCase(Time) & " " & strSvrName & VbCrLf
Else
                If (iUpdatesNeeded > AlarmYellowLevel) Then
                                strAlarm = AlarmYellow & " " & Date & " " & LCase(Time) & " " & strSvrName & VbCrLf
                Else
                                strAlarm = AlarmGreen & " " & Date & " " & LCase(Time) & " " & strSvrName & VbCrLf
                End If
End If

WScript.Echo strAlarm & VbCrLf

strOut = "<style type=""text/css"">" & VbCrLf & _
                "table.updates { width: 990; border-width: 3px; border-spacing: 0px; border-style: solid; border-color: black; border-collapse: separate; background-color: white; color: black; }" & VbCrLf & _
                "table.updates th { background-color: white; }" & VbCrLf & _
                "table.updates td.even { border-width: 1px; padding: 3px; border-style: solid; border-color: gray; background-color: #FCF6CF; color: black; }" & VbCrLf & _
                "table.updates td.odd { border-width: 1px; padding: 3px; border-style: solid; border-color: gray; background-color: #FEFEF2; color: black; }" & VbCrLf & _
                "A:link { text-decoration: none; color: blue; }" & VbCrLf & _
                "A:visited { text-decoration: none; color: purple; }" & VbCrLf & _
                "A:hover { text-decoration: underline; font-weight: bold; color: red; }" & VbCrLf & _
                "</style>" & VbCrLf & _
                "<h2>" & UCase(strSvrName) & " Needs [" & CStr(iUpdatesNeeded) & "] Windows Updates</h2>" & VbCrLf & _
                "<table class='updates'>" & _
                "<th>Title</th>" & _
                "<th>Severity</th>" & _
                "<th>Description</th>" & _
                "<th>Size(bytes)</th>" & _
                "<th>Deadline</th>" & _
                "<th>URL</th>" & _
                "<th>KBs</th>" & _
                "</tr>" & VbCrLf
                IsEven = True
Do Until oRS.EOF
                strKBs = ""
                strURL = oRS.Fields.Item("url")
                If (IsEven = True) Then
                                strClass = "class='even'"
                                IsEven = False
                Else
                                strClass = "class='odd'"
                                IsEven = True
                End If
                strOut = strOut + "<tr><td style='width: 25%' " & strClass & ">" & oRS.Fields.Item("title") & "</td>" & _
                                "<td style='width: 5%' " & strClass & ">&nbsp;" & oRS.Fields.Item("severity") & "</td>" & _
                                "<td style='width: 45%' " & strClass & ">" & oRS.Fields.Item("description") & "</td>" & _
                                "<td style='width: 5%' " & strClass & ">" & CStr(oRS.Fields.Item("size")) & "</td>" & _
                                "<td style='width: 5%' " & strClass & ">&nbsp;" & oRS.Fields.Item("deadline") & "</td>" & _
                                "<td style='width: 10%' " & strClass & "><A href='" & strURL & "' target='_blank'>" & strURL & "</a></td>" & _
                                "<td style='width: 5%' " & strClass & ">" & oRS.Fields.Item("kbs") & "</td>"
                strOut = strOut & "</tr>" & VbCrLf
                oRS.MoveNext
Loop 'each record

strOut = strOut & "</table>" & VbCrLf

WScript.Echo strOut

'Release our resources
oRS.Close
Set oShell = Nothing
Set oUpdates = Nothing
Set oResults = Nothing
Set oSearcher = Nothing

________________________________
CONFIDENTIALITY NOTICE: This email and any attachments are for the
exclusive and confidential use of the intended recipient. If you are not
the intended recipient, please do not read, distribute or take action in
reliance upon this message. If you have received this in error, please
notify us immediately by return email and promptly delete this message
and its attachments from your computer system. We do not waive
attorney-client or work product privilege by the transmission of this
message.