[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Windows update check monitor added to the Shire
- To: "'hobbit (at) hswn.dk'" <hobbit (at) hswn.dk>
- Subject: RE: Windows update check monitor added to the Shire
- From: "Storer, Raymond" <storerr (at) nibco.com>
- Date: Fri, 26 Jun 2009 16:38:27 -0400
- Accept-language: en-US
- Acceptlanguage: en-US
- References: <4A402BA0.1000802 (at) doublesparks.net> <4A42C7E9.7050205 (at) doublesparks.net> <BAY138-W2568A108E29C32B23619D39F340 (at) phx.gbl> <997a524e0906242116x51d5c01dv505af407a306c909 (at) mail.gmail.com> <BAY138-W141D730F864B0995D5B2BA9F340 (at) phx.gbl> <4A43AC27.5060904 (at) doublesparks.net> <BBA15439DC467648BBAB71E6BA4D990038F2BE8B5F (at) MERCMBX12.na.sas.com> <961092e10906251020v3da3b977t558301572970129c (at) mail.gmail.com> <BBA15439DC467648BBAB71E6BA4D990038F2BE8BD6 (at) MERCMBX12.na.sas.com> <961092e10906251040i349d99e4rb1ee045236e11f97 (at) mail.gmail.com> <997a524e0906251059m58a928b1ybe32df5e565de7c7 (at) mail.gmail.com> <9F4B8A70C3E2D142AF209DB53DBC1D5107DFCB1F (at) MUN2WSP05011.global.pioneer.com> <EBDBC7B4393B6C4F9DDADE295309C9F24AD1 (at) EX1.nibco.com>
- Thread-index: Acn1vw2ilApcgvL5RSWvM+uQDshgJwAc1NIgABJDGSAABu7+MA==
- Thread-topic: 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 & "> " & 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 & "> " & 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.