Scripts to query installed Service Packs, Patches/updates and Hotfixes
There are many known scripts which use WMI class Win32_QuickFixEngineering to enumerate hotfixes installed on a computer. These scripts can give you a list of installed updates like;
1.
This Script reports installed updates that are installed with Windows Update (v5) technology and the result will be written to %temp%\UpdateHistory.txt and then launched in Notepad.
USAGE: Cscript //nologo WUhistory.vbs
The output will look like;
Report run at 4/23/2006 2:42:14 PM
------------------------------------------------------------------
Title: Security Update for Windows XP (KB908531)
Description: A security issue has been identified in Windows Explorer that could allow an attacker to compromise your Windows-based system and gain control over it. You can help protect your computer by installing this update from Microsoft. After you install this item, you may have to restart your computer.
Date/Time in GMT: 4/18/2006 7:47:14 AM
Install mechanism: AutomaticUpdates
Install status: Succeeded
------------------------------------------------------------------
'--------------------8<----------------------
' Script that reports installed updates that are
' installed with Windows Update v5 technology
'
' Result will be written to %temp%\UpdateHistory.txt
' and then launched in Notepad
'
' Author: Torgeir Bakken
' Date 2004-08-12
'
Option Explicit
Const OverwriteIfExist = -1
Const OpenAsASCII = 0
Dim oWU, iTHCount, colUpdate, oUpdate, sStatus, iTotal
Dim iSuccess, iFailed, iAborted, iUnknown, sErrorCode
Dim oFSO, oShell, sFile, f
On Error Resume Next
Set oWU = CreateObject("Microsoft.Update.Searcher")
If Err.Number <> 0 Then
MsgBox "WU5 programming interface does not exist.", _
vbInformation + vbSystemModal, "Update history"
WScript.Quit
End If
On Error Goto 0
iTHCount = oWU.GetTotalHistoryCount
If iTHCount > 0 Then
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Wscript.Shell")
sFile = oShell.ExpandEnvironmentStrings("%TEMP%") & "\UpdateHistory.txt"
Set f = oFSO.CreateTextFile(sFile, _
OverwriteIfExist, OpenAsASCII)
iTotal = 0
iSuccess = 0
iFailed = 0
iAborted = 0
iUnknown = 0
f.WriteLine "Report run at " & Now
f.WriteLine "---------------------------------" _
& "---------------------------------"
Set colUpdate = oWU.QueryHistory(0, iTHCount)
For Each oUpdate In colUpdate
f.WriteLine "Title:" & vbTab & vbTab & vbTab & oUpdate.Title
f.WriteLine "Description:" & vbTab & vbTab & oUpdate.Description
f.WriteLine "Date/Time in GMT:" & vbTab & oUpdate.Date
f.WriteLine "Install mechanism:" & vbTab & oUpdate.ClientApplicationID
sErrorCode = ""
Select Case oUpdate.ResultCode
Case 2
sStatus = "Succeeded"
iSuccess = iSuccess + 1
Case 4
sStatus = "Failed"
iFailed = iFailed + 1
sErrorCode = oUpdate.UnmappedResultCode
Case 5
sStatus = "Aborted"
iAborted = iAborted + 1
Case Else
sStatus = "Unknown"
iUnknown = iUnknown + 1
End Select
If sStatus = "Failed" Then
f.WriteLine "Install error:" & vbTab & vbTab & sErrorCode
End If
f.WriteLine "Install status:" & vbTab & vbTab & sStatus
f.WriteLine "---------------------------------" _
& "---------------------------------"
iTotal = iTotal + 1
Next
f.WriteLine
f.WriteLine "Total number of updates found: " & iTotal
f.WriteLine "Number of updates succeeded: " & iSuccess
f.WriteLine "Number of updates failed: " & iFailed
f.WriteLine "Number of updates aborted: " & iAborted
f.Close
oShell.Run "notepad.exe " & """" & sFile & """", 1, False
Else
MsgBox "No entries found in Update History.", _
vbInformation + vbSystemModal, "Update history"
End If
'--------------------8<----------------------
2.
This script enumerate hotfixes installed on a computer and outputs some computer information.
USAGE: Cscript //nologo HotfixHistory.vbs > HotfixHistory.txt
The output will look like;
Hotfix report date: 4/23/2006 2:45:19 PM
OS version: Microsoft Windows XP Professional
SP version: Service Pack 2
OS language: English
HotFixID: KB873339
Description: Windows XP Hotfix - KB873339
InstalledBy: Administrator
InstallDate: 12/11/2005
'
' Description: Script that outputs some computer information
' and lists all installed hotfixes including installation date
'
' Author: Torgeir Bakken
' Date: 2004-10-19
'
Wscript.Echo "Hotfix report date: " & Now & vbCrLf
strComputer = "." ' use "." for local computer
Const HKLM = &H80000002
'On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
' get general info about the OS
' Caption value for different OS:
' Microsoft Windows 2000 ...
' Microsoft Windows XP ...
' Microsoft(R) Windows(R) Server 2003, ..... Edition
For Each objOperatingSystem in colSettings
strOSCaption = objOperatingSystem.Caption
Select Case True
Case InStr(1, strOSCaption, "windows 2000", vbTextCompare) > 0
strOS = "Windows 2000"
Case InStr(1, strOSCaption, "windows xp", vbTextCompare) > 0
strOS = "Windows XP"
Case InStr(1, strOSCaption, "windows(r) server 2003", vbTextCompare) > 0
strOS = "Windows Server 2003"
End Select
intOSLang = objOperatingSystem.OSLanguage
strOSLangHex = Right("000" & Hex(intOSLang), 4)
strOSServicePack = objOperatingSystem.CSDVersion
Next
Set objReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
& strComputer & "/root/default:StdRegProv")
strOSLanguage = "Unknown" ' Init value
strKeyPath = "SOFTWARE\Classes\MIME\Database\Rfc1766"
strValueName = strOSLangHex
objReg.GetStringValue HKLM, strKeyPath, strValueName, strOSLanguage
' remove unnecessary stuff
arrOSLanguage = Split(strOSLanguage, ";")
strOSLanguage = arrOSLanguage(UBound(arrOSLanguage))
If Instr(strOSLanguage, "(") > 0 Then
arrOSLanguage = Split(strOSLanguage, "(")
strOSLanguage = Trim(arrOSLanguage(0))
End If
Wscript.Echo "OS version: " & strOSCaption
Wscript.Echo "SP version: " & strOSServicePack
Wscript.Echo "OS language: " & strOSLanguage
' start enumeration of hotfixes
Wscript.Echo vbCrLf & "Hotfixes Identified:"
strRegBaseUpdate = "SOFTWARE\Microsoft\Updates\" & strOS
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_QuickFixEngineering",,48)
For Each objItem in colItems
If objItem.HotFixID <> "File 1" Then
Wscript.Echo "HotFixID: " & objItem.HotFixID
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "InstalledBy: " & objItem.InstalledBy
strInstallDate = Null ' init value
If objItem.ServicePackInEffect <> "" Then
strRegKey = strRegBaseUpdate & "\" & objItem.ServicePackInEffect _
& "\" & objItem.HotFixID
objReg.GetStringValue HKLM, strRegKey, _
"InstalledDate", strInstallDate
End If
If IsNull(strInstallDate) Then
strInstallDate = "(none found)"
End If
Wscript.Echo "InstallDate: " & strInstallDate
Wscript.Echo ' blank line
End If
Next
'--------------------8<----------------------
3.
I found this script in the community. Worth a try!
'--------------------8<----------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery _
("Select * from Win32_QuickFixEngineering")
For Each objQuickFix in colQuickFixes
Wscript.Echo "Computer: " & objQuickFix.CSName
Wscript.Echo "Description: " & objQuickFix.Description
Wscript.Echo "Hot Fix ID: " & objQuickFix.HotFixID
Wscript.Echo "Installation Date: " & objQuickFix.InstallDate
Wscript.Echo "Installed By: " & objQuickFix.InstalledBy
Next
'--------------------8<----------------------
4.
Very recently, I found this GUI utility by name WinUpdatesList.
- WinUpdatesList displays the list of all Windows updates (Service Packs and Hotfixes) installed on your local computer.
- For hotfix updates, this utility also displays the list of files updated with these hotfixes.
- In addition, it allows you to instantly open the Web link in Microsoft Web site that provides more information about the selected update, uninstall an update, copy the update information to the clipboard, or save it to text/HTML/XML file.
5.
You can also query list of updates /hotfixes installed by this simple command (one line). Replace 'server-name' with your server or your machine name;
wmic /node:'server-name' qfe GET description,FixComments,hotfixid,installedby,installedon,servicepackineffect
You can also output the result to a text / csv file;
wmic /node:'server-name' qfe GET description,FixComments,hotfixid,installedby,installedon,servicepackineffect > QFElist.txt
No comments:
Post a Comment