EnumPatchesReg.vbs

Published Mar 15 2019 01:37 PM 128 Views
Microsoft
First published on MSDN on Apr 30, 2009

'*************************************************************************
'* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
'* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'* PARTICULAR PURPOSE.
'*
'* Note: this is not an unsupported script and has not undergone testing.  Please use this script at your own risk.
'* Microsoft’s Customer Support Services (CSS/PSS) will not support issues associated with this
'*
'* Found at: http://blogs.msdn.com/clustering
'*
'* Copyright (C) 1993 - 2010.  Microsoft Corporation.  All rights reserved.
'*
'* File:    EnumPatchesReg.vbs
'*
'*
'* Version: 090518.003 - Minor fixes to the help/usage
'*
'* Version: 090423.002 - Added enumeration of QFEs for consistency.
'*     now all (and not only suspected) patches are
'*     enumerated.
'*
'* Version: 090418.001 - Initial version
'*
'* Date: 05/01/2009
'*
'* Author: Guy Teverovsky
'*
'* Purpose:     Displays details for installed patches/hotfixes
'*
'* Usage: cscript EnumPatchesReg.vbs [/computer:<NAME>] [/id:<GUID|KB>]
'*
'*   /computer:<NAME>        The name of the computer to query
'*   /id:<GUID|KB>  The GUID or KB of the hotfix to query
'*
'*   Running the script without parameters will enumerate all
'*   the patches installed on computer the script is executed on
'*
'*   Example: cscript EnumPatchesReg.vbs /id:kb968220 /computer:myserver"
'*   Example: cscript EnumPatchesReg.vbs /id:{47740627-D81D-4A45-A215-03B075A18EC7}
'*
'*
'* Requires:    Windows Scripting Host 5.6 or above, Windows 2008/Vista
'*************************************************************************

'========================================================
'Function List:
'
' DecodePatchState()
' EnumerateQFEs
' EnumProductPatches()
' GetPatchInfo()
' IsCscript()
' ShowHelp()
' StringToGUID()
' SwapCharsByPairs()
'========================================================

Option Explicit

'********************************************************************
'Define constants for the registry operations
'********************************************************************
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_PRODUCTS_SEARCH_BASE = "SOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products"


Dim g_strComputer
Dim g_strHotfixId
Dim g_objReg
Dim g_arrProductsKeys, g_strProductKey
Dim g_objAllPatches, g_strKey
Dim g_objWMIService


'********************************************************************
'* Identify if we are using CScript as the Host.
'********************************************************************
If Not IsCscript Then
Wscript.Echo "Please use Cscript as the script host."
Wscript.Echo "Cscript  " & WScript.ScriptName
Wscript.Quit
End If


'********************************************************************
'* Display Usage if called with /? parameter
'********************************************************************
If WScript.Arguments.Count = 1 Then
If WScript.Arguments(0) = "/?" Then
ShowHelp
WScript.Quit 0
End If
End If

'********************************************************************
'* Determine the target computer
'********************************************************************
If WScript.Arguments.Named.Item("computer") <> "" Then
g_strComputer = WScript.Arguments.Named.Item("computer")
Else
g_strComputer  = "."
End If

'********************************************************************
'* Connect to the registry WMI provider on target computer
'********************************************************************
Set g_objReg  = GetObject("winmgmts:{impersonationLevel=impersonate}!\" &_
g_strComputer & "rootdefault:StdRegProv")

Set g_objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & _
g_strComputer & "rootcimv2")

'********************************************************************
'* Initialize dictionary object to store the found patches
'********************************************************************
Set g_objAllPatches = CreateObject("Scripting.Dictionary")


'********************************************************************
'* Enumerate the products registry key and loop through it
'********************************************************************
g_objReg.EnumKey HKEY_LOCAL_MACHINE, REG_PRODUCTS_SEARCH_BASE, g_arrProductsKeys

For Each g_strProductKey In g_arrProductsKeys
EnumProductPatches g_strProductKey
Next

'********************************************************************
'* Enumerate installed QFEs
'********************************************************************
EnumerateQFEs

'********************************************************************
'* Provide results
'********************************************************************
If WScript.Arguments.Named.Item("id") <> "" Then
g_strHotfixId = UCase(WScript.Arguments.Named.Item("id"))
If Len(g_strHotfixId) = 8 And UCase(Left(g_strHotfixId,2)) = "KB" Then
g_strHotfixId = Mid(g_strHotfixId,3)
End If

If g_objAllPatches.Exists(g_strHotfixId) Then
WScript.Echo
WScript.Echo g_objAllPatches.Item(g_strHotfixId)
ElseIf g_objAllPatches.Exists("KB" & g_strHotfixId) Then
WScript.Echo
WScript.Echo g_objAllPatches.Item("KB" & g_strHotfixId)
Else
WScript.Echo "Failed to locate patch with ID " & g_strHotfixId
End If
Else
WScript.Echo
For Each g_strKey In g_objAllPatches.Keys
WScript.Echo String(79,"*")
WScript.Echo g_objAllPatches.Item(g_strKey)
Next
End If


'********************************************************************
'* Finalize
'********************************************************************
Set g_objAllPatches  = Nothing
Set g_objReg    = Nothing
Set g_objWMIService  = Nothing


'********************************************************************
'*
'* Function      EnumerateQFEs()
'*
'* Purpose: Enumerate all installed QFEs and add those that have
'*   not been eumerated already using registry
'*
'* Input:   None
'*
'* Output:  None
'*
'********************************************************************
Function EnumerateQFEs
Dim colQFEs
Dim objQFE
Dim strQFEInfo

Set colQFEs = g_objWMIService.ExecQuery("SELECT * FROM Win32_QuickFixEngineering")

For Each objQFE In colQFEs
If Not g_objAllPatches.Exists(objQFE.HotfixID) Then
strQFEInfo =  "HotfixId:     " & objQFE.HotfixId & VbCrLf & _
"Caption:      " & objQFE.Caption & VbCrLf & _
"Description:  " & objQFE.Description
g_objAllPatches.Add objQFE.HotfixId, strQFEInfo
End If
Next

End Function


'********************************************************************
'*
'* Function      EnumProductPatches()
'*
'* Purpose: Find patches for a given product
'*
'* Input:   strProductKey - name of product key in the registry
'*
'* Output:  None
'*
'********************************************************************
Function EnumProductPatches(strProductKey)
Dim arrPatchKeys, strPatchKey
Dim strPatchRegKey

strPatchRegKey = REG_PRODUCTS_SEARCH_BASE & "" & strProductKey & "Patches"
g_objReg.EnumKey HKEY_LOCAL_MACHINE, strPatchRegKey, arrPatchKeys

If Not IsNull(arrPatchKeys) Then
For Each strPatchKey In arrPatchKeys
GetPatchInfo strProductKey, strPatchKey
Next
End If
End Function


'********************************************************************
'*
'* Function      GetPatchInfo()
'*
'* Purpose: Pulls information from registry for a specific patch
'*
'* Input:   strProductKey  - name of product key in the registry
'*   strPatchKey  - name of patch key in the registry
'*
'* Output:  Patch details as string
'*
'********************************************************************
Function GetPatchInfo(strProductKey, strPatchKey)
Dim strPatchInfoKey, strProductInfoKey, strPatchGUID, strProductGUID
Dim strPatchName, strPatchMoreInfoURL, strPatchInstallDate
Dim strPatchType, strPatchState, strProductName
Dim dwPatchState
Dim strPatchInfo

strPatchGUID   = StringToGUID(strPatchKey)
strProductGUID   = StringToGUID(strProductKey)

strProductInfoKey  = REG_PRODUCTS_SEARCH_BASE & "" & _
strProductKey & "InstallProperties"
strPatchInfoKey  =  REG_PRODUCTS_SEARCH_BASE & "" & _
strProductKey & "Patches" & strPatchKey

g_objReg.GetStringValue HKEY_LOCAL_MACHINE, strPatchInfoKey, "DisplayName", strPatchName
g_objReg.GetStringValue HKEY_LOCAL_MACHINE, strPatchInfoKey, "MoreInfoURL", strPatchMoreInfoURL
g_objReg.GetStringValue HKEY_LOCAL_MACHINE, strPatchInfoKey, "Installed", strPatchInstallDate
g_objReg.GetDWORDValue  HKEY_LOCAL_MACHINE, strPatchInfoKey, "State", dwPatchState
g_objReg.GetStringValue HKEY_LOCAL_MACHINE, strProductInfoKey, "DisplayName", strProductName

strPatchInfo =  "Patch Name:    " & strPatchName & VbCrLf & _
"Patch Code:    " & strPatchGUID & VbCrLf & _
"More Info URL: " & strPatchMoreInfoURL & VbCrLf & _
"Patch State:   " & DecodePatchState(dwPatchState) & VbCrLf & _
"Install Date:  " & strPatchInstallDate & VbCrLf & _
"Product Name:  " & strProductName & VbCrLf & _
"Product Code:  " & strProductGUID

If Not g_objAllPatches.Exists(strPatchGUID) Then
g_objAllPatches.Add strPatchGUID, strPatchInfo
End If
End Function


'********************************************************************
'*
'* Function      DecodePatchState()
'*
'* Purpose: Translate patch state code to human readable form
'*
'* Input:   state  - numeric representation of the patch state
'*
'* Output:  Patch state as string (Installed/Superseded/Obsolete)
'*
'********************************************************************
Function DecodePatchState(state)
Select Case state
Case 1: DecodePatchState = "Installed"
Case 2: DecodePatchState = "Superseded"
Case 4: DecodePatchState = "Obsolete"
Case Else: DecodePatchState = cstr(state)
End Select
End Function


'********************************************************************
'*
'* Function      StringToGUID()
'*
'* Purpose: Converts the GUID as it is represented in registry
'*   to the form we are used to deal with
'*
'* Input:   strString  - GUID as it is represented in registry
'*
'* Output:  GUID in its standard form
'*   i.e.: {47740627-D81D-4A45-A215-03B075A18EC7}
'*
'********************************************************************
Function StringToGUID(strString)
Dim arrGUIDParts(6)
Dim strGUID

If Len(strstring) <> 32 Then
StringToGUID = ""
Exit Function
End If

arrGUIDParts(0) = Mid(strString,1,8)
arrGUIDParts(1) = Mid(strString,9,4)
arrGUIDParts(2) = Mid(strString,13,4)
arrGUIDParts(3) = Mid(strString,17,4)
arrGUIDParts(4) = Mid(strString,21,12)

arrGUIDParts(0) = StrReverse(arrGUIDParts(0))
arrGUIDParts(1) = StrReverse(arrGUIDParts(1))
arrGUIDParts(2) = StrReverse(arrGUIDParts(2))
arrGUIDParts(3) = SwapCharsByPairs(arrGUIDParts(3))
arrGUIDParts(4) = SwapCharsByPairs(arrGUIDParts(4))

StringToGUID =  "{" & arrGUIDParts(0) & "-" & _
arrGUIDParts(1) & "-" & _
arrGUIDParts(2) & "-" & _
arrGUIDParts(3) & "-" & _
arrGUIDParts(4) & "}"
End Function

'********************************************************************
'*
'* Function      SwapCharsByPairs()
'*
'* Purpose: Helper function for operations on strings
'*
'* Input:   strString  - some text
'*
'* Output:  text after some logic applied
'*
'********************************************************************
Function SwapCharsByPairs(strString)
Dim i, arrChars()
Dim intStrLen : intStrLen = Len(strString)

If intStrLen < 2 Then
SwapCharsByPairs = strString
Exit Function
End If

ReDim arrChars(intStrLen - 1)

For i = 0 To intStrLen - 2
arrChars(i)  = Mid(strString,i+2,1)
arrChars(i+1)  = Mid(strString,i+1,1)
i = i + 1
Next
SwapCharsByPairs = Join(arrChars,"")
End Function

'********************************************************************
'*
'* Function      ShowHelp()
'*
'* Purpose: Shows script usage/help
'*
'* Input:   None
'*
'* Output:  None
'*
'********************************************************************
Function ShowHelp
WScript.Echo
WScript.Echo "  Displays details for installed patches/hotfixes"
WScript.Echo
WScript.Echo "  Usage: cscript " & WScript.ScriptName & " [/computer:<NAME>] [/id:<GUID|KB>]"
WScript.Echo
WScript.Echo " /computer:<NAME> The name of the computer to query. If the parameter"
WScript.Echo "    is not specified, the script will default to localhost"
WScript.Echo " /id:<GUID|KB>  The GUID or KB of the hotfix to query."
WScript.Echo "    If parameter is not specified, the script will enumerate"
WScript.Echo "    all the patches installed."
WScript.Echo
WScript.Echo " Running the script without parameters will enumerate all"
WScript.Echo " the patches installed on computer the script is executed on."
WScript.Echo
WScript.Echo "  Example: cscript EnumPatchesReg.vbs /id:kb968220 /computer:myserver"
WScript.Echo "  Example: cscript EnumPatchesReg.vbs /id:{47740627-D81D-4A45-A215-03B075A18EC7}"
WScript.Echo
End Function


'********************************************************************
'*
'* Function      IsCscript()
'*
'* Purpose: Determines which program is used to run this script.
'*
'* Input:   None
'*
'* Output:  Return True if the script host is Cscript.
'*
'********************************************************************
Function IsCscript()

On Error Resume Next
'********************************************************************
'Define constants
'********************************************************************
CONST CONST_ERROR               = 0
CONST CONST_WSCRIPT             = 1
CONST CONST_CSCRIPT             = 2
CONST CONST_SHOW_USAGE          = 3
CONST CONST_LIST                = 4

Dim strFullName, strCommand, i, j, intStatus

Err.Clear
strFullName = WScript.FullName

If Err.Number then
Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & " occurred." )
If Err.Description <> "" Then
Call Wscript.Echo( "Error description: " & Err.Description & "." )
End If
intStatus =  CONST_ERROR
End If

i = InStr(1, strFullName, ".exe", 1)
If i = 0 Then
intStatus =  CONST_ERROR
Else
j = InStrRev(strFullName, "", i, 1)
If j = 0 Then
intStatus =  CONST_ERROR
Else
strCommand = Mid(strFullName, j+1, i-j-1)
Select Case LCase(strCommand)
Case "cscript"
intStatus = CONST_CSCRIPT
Case "wscript"
intStatus = CONST_WSCRIPT
Case Else       'should never happen
Call Wscript.Echo( "An unexpected program was used to " _
& "run this script." )
Call Wscript.Echo( "Only CScript.Exe or WScript.Exe can " _
& "be used to run this script." )
intStatus = CONST_ERROR
End Select
End If
End If

If intStatus <> CONST_CSCRIPT Then
IsCscript = False
Else
IsCscript = True
End If

On Error GoTo 0
End Function


%3CLINGO-SUB%20id%3D%22lingo-sub-371397%22%20slang%3D%22en-US%22%3EEnumPatchesReg.vbs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-371397%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Apr%2030%2C%202009%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3E'*************************************************************************%20%3CBR%20%2F%3E'*%20THIS%20CODE%20AND%20INFORMATION%20IS%20PROVIDED%20%22AS%20IS%22%20WITHOUT%20WARRANTY%20OF%20%3CBR%20%2F%3E'*%20ANY%20KIND%2C%20EITHER%20EXPRESSED%20OR%20IMPLIED%2C%20INCLUDING%20BUT%20NOT%20LIMITED%20%3CBR%20%2F%3E'*%20TO%20THE%20IMPLIED%20WARRANTIES%20OF%20MERCHANTABILITY%20AND%2FOR%20FITNESS%20FOR%20A%20%3CBR%20%2F%3E'*%20PARTICULAR%20PURPOSE.%20%3CBR%20%2F%3E%20'*%20%3CBR%20%2F%3E'*%20Note%3A%20this%20is%20not%20an%20unsupported%20script%20and%20has%20not%20undergone%20testing.%26nbsp%3B%20Please%20use%20this%20script%20at%20your%20own%20risk.%20%3CBR%20%2F%3E%20'*%20Microsoft%E2%80%99s%20Customer%20Support%20Services%20(CSS%2FPSS)%20will%20not%20support%20issues%20associated%20with%20this%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Found%20at%3A%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fclustering%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fblogs.msdn.com%2Fclustering%20%3C%2FA%3E%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Copyright%20(C)%201993%20-%202010.%26nbsp%3B%20Microsoft%20Corporation.%26nbsp%3B%20All%20rights%20reserved.%20%3CBR%20%2F%3E%20'*%20%3CBR%20%2F%3E'*%20File%3A%26nbsp%3B%26nbsp%3B%20%26nbsp%3BEnumPatchesReg.vbs%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Version%3A%26nbsp%3B090518.003%26nbsp%3B-%26nbsp%3BMinor%20fixes%20to%20the%20help%2Fusage%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Version%3A%26nbsp%3B090423.002%26nbsp%3B-%26nbsp%3BAdded%20enumeration%20of%20QFEs%20for%20consistency.%20%3CBR%20%2F%3E%20'*%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bnow%20all%20(and%20not%20only%20suspected)%20patches%20are%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Benumerated.%20%3CBR%20%2F%3E%20'*%20%3CBR%20%2F%3E'*%20Version%3A%26nbsp%3B090418.001%26nbsp%3B-%26nbsp%3BInitial%20version%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Date%3A%26nbsp%3B05%2F01%2F2009%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Author%3A%26nbsp%3BGuy%20Teverovsky%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Displays%20details%20for%20installed%20patches%2Fhotfixes%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Usage%3A%26nbsp%3Bcscript%20EnumPatchesReg.vbs%20%5B%2Fcomputer%3A%3CNAME%3E%5D%20%5B%2Fid%3A%3CGUID%3E%5D%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3B%2Fcomputer%3A%3CNAME%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20The%20name%20of%20the%20computer%20to%20query%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3B%2Fid%3A%3CGUID%3E%26nbsp%3B%26nbsp%3BThe%20GUID%20or%20KB%20of%20the%20hotfix%20to%20query%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3BRunning%20the%20script%20without%20parameters%20will%20enumerate%20all%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3Bthe%20patches%20installed%20on%20computer%20the%20script%20is%20executed%20on%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3BExample%3A%20cscript%20EnumPatchesReg.vbs%20%2Fid%3Akb968220%20%2Fcomputer%3Amyserver%22%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3BExample%3A%20cscript%20EnumPatchesReg.vbs%20%2Fid%3A%7B47740627-D81D-4A45-A215-03B075A18EC7%7D%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Requires%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Windows%20Scripting%20Host%205.6%20or%20above%2C%20Windows%202008%2FVista%20%3CBR%20%2F%3E'*************************************************************************%3C%2FGUID%3E%3C%2FNAME%3E%3C%2FGUID%3E%3C%2FNAME%3E%3C%2FP%3E%0A%20%20%3CP%3E'%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E'Function%20List%3A%20%3CBR%20%2F%3E'%20%3CBR%20%2F%3E'%26nbsp%3BDecodePatchState()%20%3CBR%20%2F%3E'%26nbsp%3BEnumerateQFEs%20%3CBR%20%2F%3E'%26nbsp%3BEnumProductPatches()%20%3CBR%20%2F%3E'%26nbsp%3BGetPatchInfo()%20%3CBR%20%2F%3E'%26nbsp%3BIsCscript()%20%3CBR%20%2F%3E'%26nbsp%3BShowHelp()%20%3CBR%20%2F%3E'%26nbsp%3BStringToGUID()%20%3CBR%20%2F%3E'%26nbsp%3BSwapCharsByPairs()%20%3CBR%20%2F%3E'%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FP%3E%0A%20%20%3CP%3EOption%20Explicit%3C%2FP%3E%0A%20%20%3CP%3E'********************************************************************%20%3CBR%20%2F%3E'Define%20constants%20for%20the%20registry%20operations%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EConst%20HKEY_LOCAL_MACHINE%20%3D%20%26amp%3BH80000002%20%3CBR%20%2F%3EConst%20REG_PRODUCTS_SEARCH_BASE%20%3D%20%22SOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products%22%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20Dim%20g_strComputer%20%3CBR%20%2F%3EDim%20g_strHotfixId%20%3CBR%20%2F%3EDim%20g_objReg%20%3CBR%20%2F%3EDim%20g_arrProductsKeys%2C%20g_strProductKey%20%3CBR%20%2F%3EDim%20g_objAllPatches%2C%20g_strKey%20%3CBR%20%2F%3EDim%20g_objWMIService%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20Identify%20if%20we%20are%20using%20CScript%20as%20the%20Host.%20%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3EIf%20Not%20IsCscript%20Then%20%3CBR%20%2F%3EWscript.Echo%20%22Please%20use%20Cscript%20as%20the%20script%20host.%22%20%3CBR%20%2F%3EWscript.Echo%20%22Cscript%26nbsp%3B%20%22%20%26amp%3B%20WScript.ScriptName%20%3CBR%20%2F%3EWscript.Quit%20%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20Display%20Usage%20if%20called%20with%20%2F%3F%20parameter%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EIf%20WScript.Arguments.Count%20%3D%201%20Then%20%3CBR%20%2F%3EIf%20WScript.Arguments(0)%20%3D%20%22%2F%3F%22%20Then%20%3CBR%20%2F%3EShowHelp%20%3CBR%20%2F%3EWScript.Quit%200%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%0A%20%20%3CP%3E'********************************************************************%20%3CBR%20%2F%3E'*%20Determine%20the%20target%20computer%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EIf%20WScript.Arguments.Named.Item(%22computer%22)%20%26lt%3B%26gt%3B%20%22%22%20Then%20%3CBR%20%2F%3Eg_strComputer%20%3D%20WScript.Arguments.Named.Item(%22computer%22)%20%3CBR%20%2F%3EElse%20%3CBR%20%2F%3Eg_strComputer%26nbsp%3B%26nbsp%3B%3D%20%22.%22%20%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%0A%20%20%3CP%3E'********************************************************************%20%3CBR%20%2F%3E'*%20Connect%20to%20the%20registry%20WMI%20provider%20on%20target%20computer%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3ESet%20g_objReg%26nbsp%3B%26nbsp%3B%3D%20GetObject(%22winmgmts%3A%7BimpersonationLevel%3Dimpersonate%7D!%5C%22%20%26amp%3B_%20%3CBR%20%2F%3Eg_strComputer%20%26amp%3B%20%22rootdefault%3AStdRegProv%22)%3C%2FP%3E%0A%20%20%3CP%3ESet%20g_objWMIService%20%3D%20GetObject(%22winmgmts%3A%7BimpersonationLevel%3Dimpersonate%7D!%5C%22%20%26amp%3B%20_%20%3CBR%20%2F%3Eg_strComputer%20%26amp%3B%20%22rootcimv2%22)%20%3CBR%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E'********************************************************************%20%3CBR%20%2F%3E'*%20Initialize%20dictionary%20object%20to%20store%20the%20found%20patches%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3ESet%20g_objAllPatches%20%3D%20CreateObject(%22Scripting.Dictionary%22)%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20Enumerate%20the%20products%20registry%20key%20and%20loop%20through%20it%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3Eg_objReg.EnumKey%20HKEY_LOCAL_MACHINE%2C%20REG_PRODUCTS_SEARCH_BASE%2C%20g_arrProductsKeys%3C%2FP%3E%0A%20%20%3CP%3EFor%20Each%20g_strProductKey%20In%20g_arrProductsKeys%20%3CBR%20%2F%3EEnumProductPatches%20g_strProductKey%20%3CBR%20%2F%3ENext%3C%2FP%3E%0A%20%20%3CP%3E'********************************************************************%20%3CBR%20%2F%3E'*%20Enumerate%20installed%20QFEs%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EEnumerateQFEs%3C%2FP%3E%0A%20%20%3CP%3E'********************************************************************%20%3CBR%20%2F%3E'*%20Provide%20results%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EIf%20WScript.Arguments.Named.Item(%22id%22)%20%26lt%3B%26gt%3B%20%22%22%20Then%20%3CBR%20%2F%3Eg_strHotfixId%20%3D%20UCase(WScript.Arguments.Named.Item(%22id%22))%20%3CBR%20%2F%3EIf%20Len(g_strHotfixId)%20%3D%208%20And%20UCase(Left(g_strHotfixId%2C2))%20%3D%20%22KB%22%20Then%20%3CBR%20%2F%3Eg_strHotfixId%20%3D%20Mid(g_strHotfixId%2C3)%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20g_objAllPatches.Exists(g_strHotfixId)%20Then%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EWScript.Echo%20g_objAllPatches.Item(g_strHotfixId)%20%3CBR%20%2F%3EElseIf%20g_objAllPatches.Exists(%22KB%22%20%26amp%3B%20g_strHotfixId)%20Then%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EWScript.Echo%20g_objAllPatches.Item(%22KB%22%20%26amp%3B%20g_strHotfixId)%20%3CBR%20%2F%3EElse%20%3CBR%20%2F%3EWScript.Echo%20%22Failed%20to%20locate%20patch%20with%20ID%20%22%20%26amp%3B%20g_strHotfixId%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3EElse%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EFor%20Each%20g_strKey%20In%20g_objAllPatches.Keys%20%3CBR%20%2F%3EWScript.Echo%20String(79%2C%22*%22)%20%3CBR%20%2F%3EWScript.Echo%20g_objAllPatches.Item(g_strKey)%20%3CBR%20%2F%3ENext%20%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20Finalize%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3ESet%20g_objAllPatches%20%26nbsp%3B%3D%20Nothing%20%3CBR%20%2F%3ESet%20g_objReg%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%3D%20Nothing%20%3CBR%20%2F%3ESet%20g_objWMIService%26nbsp%3B%26nbsp%3B%3D%20Nothing%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Function%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20EnumerateQFEs()%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%20Enumerate%20all%20installed%20QFEs%20and%20add%20those%20that%20have%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3Bnot%20been%20eumerated%20already%20using%20registry%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Input%3A%26nbsp%3B%26nbsp%3B%20None%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Output%3A%26nbsp%3B%20None%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EFunction%20EnumerateQFEs%20%3CBR%20%2F%3EDim%20colQFEs%20%3CBR%20%2F%3EDim%20objQFE%20%3CBR%20%2F%3EDim%20strQFEInfo%20%3CBR%20%2F%3E%3CBR%20%2F%3ESet%20colQFEs%20%3D%20g_objWMIService.ExecQuery(%22SELECT%20*%20FROM%20Win32_QuickFixEngineering%22)%20%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20Each%20objQFE%20In%20colQFEs%20%3CBR%20%2F%3EIf%20Not%20g_objAllPatches.Exists(objQFE.HotfixID)%20Then%20%3CBR%20%2F%3EstrQFEInfo%20%3D%20%26nbsp%3B%22HotfixId%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22%20%26amp%3B%20objQFE.HotfixId%20%26amp%3B%20VbCrLf%20%26amp%3B%20_%20%3CBR%20%2F%3E%22Caption%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22%20%26amp%3B%20objQFE.Caption%20%26amp%3B%20VbCrLf%20%26amp%3B%20_%20%3CBR%20%2F%3E%22Description%3A%26nbsp%3B%20%22%20%26amp%3B%20objQFE.Description%20%3CBR%20%2F%3Eg_objAllPatches.Add%20objQFE.HotfixId%2C%20strQFEInfo%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3ENext%20%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Function%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20EnumProductPatches()%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%20Find%20patches%20for%20a%20given%20product%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Input%3A%26nbsp%3B%26nbsp%3B%20strProductKey%20-%20name%20of%20product%20key%20in%20the%20registry%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Output%3A%26nbsp%3B%20None%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EFunction%20EnumProductPatches(strProductKey)%20%3CBR%20%2F%3EDim%20arrPatchKeys%2C%20strPatchKey%20%3CBR%20%2F%3EDim%20strPatchRegKey%20%3CBR%20%2F%3E%3CBR%20%2F%3EstrPatchRegKey%20%3D%20REG_PRODUCTS_SEARCH_BASE%20%26amp%3B%20%22%22%20%26amp%3B%20strProductKey%20%26amp%3B%20%22Patches%22%20%3CBR%20%2F%3Eg_objReg.EnumKey%20HKEY_LOCAL_MACHINE%2C%20strPatchRegKey%2C%20arrPatchKeys%20%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20Not%20IsNull(arrPatchKeys)%20Then%20%3CBR%20%2F%3EFor%20Each%20strPatchKey%20In%20arrPatchKeys%20%3CBR%20%2F%3EGetPatchInfo%20strProductKey%2C%20strPatchKey%20%3CBR%20%2F%3ENext%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Function%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20GetPatchInfo()%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%20Pulls%20information%20from%20registry%20for%20a%20specific%20patch%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Input%3A%26nbsp%3B%26nbsp%3B%20strProductKey%20%26nbsp%3B-%20name%20of%20product%20key%20in%20the%20registry%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3BstrPatchKey%20%26nbsp%3B-%20name%20of%20patch%20key%20in%20the%20registry%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Output%3A%26nbsp%3B%20Patch%20details%20as%20string%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EFunction%20GetPatchInfo(strProductKey%2C%20strPatchKey)%20%3CBR%20%2F%3EDim%20strPatchInfoKey%2C%20strProductInfoKey%2C%20strPatchGUID%2C%20strProductGUID%20%3CBR%20%2F%3EDim%20strPatchName%2C%20strPatchMoreInfoURL%2C%20strPatchInstallDate%20%3CBR%20%2F%3EDim%20strPatchType%2C%20strPatchState%2C%20strProductName%20%3CBR%20%2F%3EDim%20dwPatchState%20%3CBR%20%2F%3EDim%20strPatchInfo%20%3CBR%20%2F%3E%3CBR%20%2F%3EstrPatchGUID%20%26nbsp%3B%26nbsp%3B%3D%20StringToGUID(strPatchKey)%20%3CBR%20%2F%3EstrProductGUID%20%26nbsp%3B%26nbsp%3B%3D%20StringToGUID(strProductKey)%3C%2FP%3E%0A%20%20%3CP%3EstrProductInfoKey%20%26nbsp%3B%3D%20REG_PRODUCTS_SEARCH_BASE%20%26amp%3B%20%22%22%20%26amp%3B%20_%20%3CBR%20%2F%3EstrProductKey%20%26amp%3B%20%22InstallProperties%22%20%3CBR%20%2F%3EstrPatchInfoKey%20%26nbsp%3B%3D%20%26nbsp%3BREG_PRODUCTS_SEARCH_BASE%20%26amp%3B%20%22%22%20%26amp%3B%20_%20%3CBR%20%2F%3EstrProductKey%20%26amp%3B%20%22Patches%22%20%26amp%3B%20strPatchKey%20%3CBR%20%2F%3E%3CBR%20%2F%3Eg_objReg.GetStringValue%20HKEY_LOCAL_MACHINE%2C%20strPatchInfoKey%2C%20%22DisplayName%22%2C%20strPatchName%20%3CBR%20%2F%3Eg_objReg.GetStringValue%20HKEY_LOCAL_MACHINE%2C%20strPatchInfoKey%2C%20%22MoreInfoURL%22%2C%20strPatchMoreInfoURL%20%3CBR%20%2F%3Eg_objReg.GetStringValue%20HKEY_LOCAL_MACHINE%2C%20strPatchInfoKey%2C%20%22Installed%22%2C%20strPatchInstallDate%20%3CBR%20%2F%3Eg_objReg.GetDWORDValue%26nbsp%3B%20HKEY_LOCAL_MACHINE%2C%20strPatchInfoKey%2C%20%22State%22%2C%20dwPatchState%20%3CBR%20%2F%3Eg_objReg.GetStringValue%20HKEY_LOCAL_MACHINE%2C%20strProductInfoKey%2C%20%22DisplayName%22%2C%20strProductName%20%3CBR%20%2F%3E%3CBR%20%2F%3EstrPatchInfo%20%3D%20%26nbsp%3B%22Patch%20Name%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22%20%26amp%3B%20strPatchName%20%26amp%3B%20VbCrLf%20%26amp%3B%20_%20%3CBR%20%2F%3E%22Patch%20Code%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22%20%26amp%3B%20strPatchGUID%20%26amp%3B%20VbCrLf%20%26amp%3B%20_%20%3CBR%20%2F%3E%22More%20Info%20URL%3A%20%22%20%26amp%3B%20strPatchMoreInfoURL%20%26amp%3B%20VbCrLf%20%26amp%3B%20_%20%3CBR%20%2F%3E%22Patch%20State%3A%26nbsp%3B%26nbsp%3B%20%22%20%26amp%3B%20DecodePatchState(dwPatchState)%20%26amp%3B%20VbCrLf%20%26amp%3B%20_%20%3CBR%20%2F%3E%22Install%20Date%3A%26nbsp%3B%20%22%20%26amp%3B%20strPatchInstallDate%20%26amp%3B%20VbCrLf%20%26amp%3B%20_%20%3CBR%20%2F%3E%22Product%20Name%3A%26nbsp%3B%20%22%20%26amp%3B%20strProductName%20%26amp%3B%20VbCrLf%20%26amp%3B%20_%20%3CBR%20%2F%3E%22Product%20Code%3A%26nbsp%3B%20%22%20%26amp%3B%20strProductGUID%3C%2FP%3E%0A%20%20%3CP%3EIf%20Not%20g_objAllPatches.Exists(strPatchGUID)%20Then%20%3CBR%20%2F%3Eg_objAllPatches.Add%20strPatchGUID%2C%20strPatchInfo%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Function%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20DecodePatchState()%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%20Translate%20patch%20state%20code%20to%20human%20readable%20form%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Input%3A%26nbsp%3B%26nbsp%3B%20state%20%26nbsp%3B-%20numeric%20representation%20of%20the%20patch%20state%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Output%3A%26nbsp%3B%20Patch%20state%20as%20string%20(Installed%2FSuperseded%2FObsolete)%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EFunction%20DecodePatchState(state)%20%3CBR%20%2F%3ESelect%20Case%20state%20%3CBR%20%2F%3ECase%201%3A%26nbsp%3BDecodePatchState%20%3D%20%22Installed%22%20%3CBR%20%2F%3ECase%202%3A%20DecodePatchState%20%3D%20%22Superseded%22%20%3CBR%20%2F%3ECase%204%3A%20DecodePatchState%20%3D%20%22Obsolete%22%20%3CBR%20%2F%3ECase%20Else%3A%20DecodePatchState%20%3D%20cstr(state)%20%3CBR%20%2F%3EEnd%20Select%20%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Function%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20StringToGUID()%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%20Converts%20the%20GUID%20as%20it%20is%20represented%20in%20registry%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3Bto%20the%20form%20we%20are%20used%20to%20deal%20with%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Input%3A%26nbsp%3B%26nbsp%3B%20strString%20%26nbsp%3B-%20GUID%20as%20it%20is%20represented%20in%20registry%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Output%3A%26nbsp%3B%20GUID%20in%20its%20standard%20form%20%3CBR%20%2F%3E'*%26nbsp%3B%26nbsp%3B%26nbsp%3Bi.e.%3A%20%7B47740627-D81D-4A45-A215-03B075A18EC7%7D%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EFunction%20StringToGUID(strString)%20%3CBR%20%2F%3EDim%20arrGUIDParts(6)%20%3CBR%20%2F%3EDim%20strGUID%20%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20Len(strstring)%20%26lt%3B%26gt%3B%2032%20Then%20%3CBR%20%2F%3EStringToGUID%20%3D%20%22%22%20%3CBR%20%2F%3EExit%20Function%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3E%3CBR%20%2F%3EarrGUIDParts(0)%20%3D%20Mid(strString%2C1%2C8)%20%3CBR%20%2F%3EarrGUIDParts(1)%20%3D%20Mid(strString%2C9%2C4)%20%3CBR%20%2F%3EarrGUIDParts(2)%20%3D%20Mid(strString%2C13%2C4)%20%3CBR%20%2F%3EarrGUIDParts(3)%20%3D%20Mid(strString%2C17%2C4)%20%3CBR%20%2F%3EarrGUIDParts(4)%20%3D%20Mid(strString%2C21%2C12)%20%3CBR%20%2F%3E%3CBR%20%2F%3EarrGUIDParts(0)%20%3D%20StrReverse(arrGUIDParts(0))%20%3CBR%20%2F%3EarrGUIDParts(1)%20%3D%20StrReverse(arrGUIDParts(1))%20%3CBR%20%2F%3EarrGUIDParts(2)%20%3D%20StrReverse(arrGUIDParts(2))%20%3CBR%20%2F%3EarrGUIDParts(3)%20%3D%20SwapCharsByPairs(arrGUIDParts(3))%20%3CBR%20%2F%3EarrGUIDParts(4)%20%3D%20SwapCharsByPairs(arrGUIDParts(4))%20%3CBR%20%2F%3E%3CBR%20%2F%3EStringToGUID%20%3D%20%26nbsp%3B%22%7B%22%20%26amp%3B%20arrGUIDParts(0)%20%26amp%3B%20%22-%22%20%26amp%3B%20_%20%3CBR%20%2F%3EarrGUIDParts(1)%20%26amp%3B%20%22-%22%20%26amp%3B%20_%20%3CBR%20%2F%3EarrGUIDParts(2)%20%26amp%3B%20%22-%22%20%26amp%3B%20_%20%3CBR%20%2F%3EarrGUIDParts(3)%20%26amp%3B%20%22-%22%20%26amp%3B%20_%20%3CBR%20%2F%3EarrGUIDParts(4)%20%26amp%3B%20%22%7D%22%20%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%0A%20%20%3CP%3E'********************************************************************%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Function%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20SwapCharsByPairs()%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%20Helper%20function%20for%20operations%20on%20strings%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Input%3A%26nbsp%3B%26nbsp%3B%20strString%20%26nbsp%3B-%20some%20text%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Output%3A%26nbsp%3B%20text%20after%20some%20logic%20applied%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EFunction%20SwapCharsByPairs(strString)%20%3CBR%20%2F%3EDim%20i%2C%20arrChars()%20%3CBR%20%2F%3EDim%20intStrLen%20%3A%20intStrLen%20%3D%20Len(strString)%20%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20intStrLen%20%26lt%3B%202%20Then%20%3CBR%20%2F%3ESwapCharsByPairs%20%3D%20strString%20%3CBR%20%2F%3EExit%20Function%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3E%3CBR%20%2F%3EReDim%20arrChars(intStrLen%20-%201)%20%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20i%20%3D%200%20To%20intStrLen%20-%202%20%3CBR%20%2F%3EarrChars(i)%20%26nbsp%3B%3D%20Mid(strString%2Ci%2B2%2C1)%20%3CBR%20%2F%3EarrChars(i%2B1)%20%26nbsp%3B%3D%20Mid(strString%2Ci%2B1%2C1)%20%3CBR%20%2F%3Ei%20%3D%20i%20%2B%201%20%3CBR%20%2F%3ENext%20%3CBR%20%2F%3ESwapCharsByPairs%20%3D%20Join(arrChars%2C%22%22)%20%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%0A%20%20%3CP%3E'********************************************************************%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Function%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ShowHelp()%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%20Shows%20script%20usage%2Fhelp%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Input%3A%26nbsp%3B%26nbsp%3B%20None%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Output%3A%26nbsp%3B%20None%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EFunction%20ShowHelp%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%20Displays%20details%20for%20installed%20patches%2Fhotfixes%22%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%20Usage%3A%20cscript%20%22%20%26amp%3B%20WScript.ScriptName%20%26amp%3B%20%22%20%5B%2Fcomputer%3A%3CNAME%3E%5D%20%5B%2Fid%3A%3CGUID%3E%5D%22%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%2Fcomputer%3A%3CNAME%3E%26nbsp%3BThe%20name%20of%20the%20computer%20to%20query.%20If%20the%20parameter%22%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bis%20not%20specified%2C%20the%20script%20will%20default%20to%20localhost%22%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%2Fid%3A%3CGUID%3E%26nbsp%3B%26nbsp%3BThe%20GUID%20or%20KB%20of%20the%20hotfix%20to%20query.%22%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BIf%20parameter%20is%20not%20specified%2C%20the%20script%20will%20enumerate%22%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Ball%20the%20patches%20installed.%22%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3BRunning%20the%20script%20without%20parameters%20will%20enumerate%20all%22%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3Bthe%20patches%20installed%20on%20computer%20the%20script%20is%20executed%20on.%22%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%20Example%3A%20cscript%20EnumPatchesReg.vbs%20%2Fid%3Akb968220%20%2Fcomputer%3Amyserver%22%20%3CBR%20%2F%3EWScript.Echo%20%22%26nbsp%3B%20Example%3A%20cscript%20EnumPatchesReg.vbs%20%2Fid%3A%7B47740627-D81D-4A45-A215-03B075A18EC7%7D%22%20%3CBR%20%2F%3EWScript.Echo%20%3CBR%20%2F%3EEnd%20Function%3C%2FGUID%3E%3C%2FNAME%3E%3C%2FGUID%3E%3C%2FNAME%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CBR%20%2F%3E%20'********************************************************************%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Function%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20IsCscript()%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Purpose%3A%20Determines%20which%20program%20is%20used%20to%20run%20this%20script.%20%3CBR%20%2F%3E%20'*%20%3CBR%20%2F%3E'*%20Input%3A%26nbsp%3B%26nbsp%3B%20None%20%3CBR%20%2F%3E'*%20%3CBR%20%2F%3E'*%20Output%3A%26nbsp%3B%20Return%20True%20if%20the%20script%20host%20is%20Cscript.%20%3CBR%20%2F%3E%20'*%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3EFunction%20IsCscript()%3C%2FP%3E%0A%20%20%3CP%3EOn%20Error%20Resume%20Next%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3E'Define%20constants%20%3CBR%20%2F%3E'********************************************************************%20%3CBR%20%2F%3ECONST%20CONST_ERROR%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%200%20%3CBR%20%2F%3ECONST%20CONST_WSCRIPT%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%201%20%3CBR%20%2F%3ECONST%20CONST_CSCRIPT%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%202%20%3CBR%20%2F%3ECONST%20CONST_SHOW_USAGE%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%203%20%3CBR%20%2F%3ECONST%20CONST_LIST%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%204%3C%2FP%3E%0A%20%20%3CP%3EDim%20strFullName%2C%20strCommand%2C%20i%2C%20j%2C%20intStatus%20%3CBR%20%2F%3E%3CBR%20%2F%3EErr.Clear%20%3CBR%20%2F%3EstrFullName%20%3D%20WScript.FullName%3C%2FP%3E%0A%20%20%3CP%3EIf%20Err.Number%20then%20%3CBR%20%2F%3ECall%20Wscript.Echo(%20%22Error%200x%22%20%26amp%3B%20CStr(Hex(Err.Number))%20%26amp%3B%20%22%20occurred.%22%20)%20%3CBR%20%2F%3EIf%20Err.Description%20%26lt%3B%26gt%3B%20%22%22%20Then%20%3CBR%20%2F%3ECall%20Wscript.Echo(%20%22Error%20description%3A%20%22%20%26amp%3B%20Err.Description%20%26amp%3B%20%22.%22%20)%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3EintStatus%20%3D%26nbsp%3B%20CONST_ERROR%20%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%0A%20%20%3CP%3Ei%20%3D%20InStr(1%2C%20strFullName%2C%20%22.exe%22%2C%201)%20%3CBR%20%2F%3EIf%20i%20%3D%200%20Then%20%3CBR%20%2F%3EintStatus%20%3D%26nbsp%3B%20CONST_ERROR%20%3CBR%20%2F%3EElse%20%3CBR%20%2F%3Ej%20%3D%20InStrRev(strFullName%2C%20%22%22%2C%20i%2C%201)%20%3CBR%20%2F%3EIf%20j%20%3D%200%20Then%20%3CBR%20%2F%3EintStatus%20%3D%26nbsp%3B%20CONST_ERROR%20%3CBR%20%2F%3EElse%20%3CBR%20%2F%3EstrCommand%20%3D%20Mid(strFullName%2C%20j%2B1%2C%20i-j-1)%20%3CBR%20%2F%3ESelect%20Case%20LCase(strCommand)%20%3CBR%20%2F%3ECase%20%22cscript%22%20%3CBR%20%2F%3EintStatus%20%3D%20CONST_CSCRIPT%20%3CBR%20%2F%3ECase%20%22wscript%22%20%3CBR%20%2F%3EintStatus%20%3D%20CONST_WSCRIPT%20%3CBR%20%2F%3ECase%20Else%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20'should%20never%20happen%20%3CBR%20%2F%3ECall%20Wscript.Echo(%20%22An%20unexpected%20program%20was%20used%20to%20%22%20_%20%3CBR%20%2F%3E%26amp%3B%20%22run%20this%20script.%22%20)%20%3CBR%20%2F%3ECall%20Wscript.Echo(%20%22Only%20CScript.Exe%20or%20WScript.Exe%20can%20%22%20_%20%3CBR%20%2F%3E%26amp%3B%20%22be%20used%20to%20run%20this%20script.%22%20)%20%3CBR%20%2F%3EintStatus%20%3D%20CONST_ERROR%20%3CBR%20%2F%3EEnd%20Select%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%0A%20%20%3CP%3EIf%20intStatus%20%26lt%3B%26gt%3B%20CONST_CSCRIPT%20Then%20%3CBR%20%2F%3EIsCscript%20%3D%20False%20%3CBR%20%2F%3EElse%20%3CBR%20%2F%3EIsCscript%20%3D%20True%20%3CBR%20%2F%3EEnd%20If%20%3CBR%20%2F%3E%3CBR%20%2F%3EOn%20Error%20GoTo%200%20%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-371397%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Apr%2030%2C%202009%20'*************************************************************************'*%20THIS%20CODE%20AND%20INFORMATION%20IS%20PROVIDED%20%22AS%20IS%22%20WITHOUT%20WARRANTY%20OF'*%20ANY%20KIND%2C%20EITHER%20EXPRESSED%20OR%20IMPLIED%2C%20INCLUDING%20BUT%20NOT%20LIMITED'*%20TO%20THE%20IMPLIED%20WARRANTIES%20OF%20MERCHANTABILITY%20AND%2FOR%20FITNESS%20FOR%20A'*%20PARTICULAR%20PURPOSE.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-371397%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPages%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 15 2019 01:37 PM
Updated by: