WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Enumerate Windows Updates

 Keywords: list updates Windows install enumerate 

Sample 1

;Winbatch 2007C -
;script to obtain Windows Update, using COM, no error-checking
;results output to text file
;
;Stan Littlefield, January 9, 2008
;//////////////////////////////////////////////////////////////////////////////////////
ResultCodes= "not started,in progress,succeeded,succeeded with errors,failed,aborted"
Operations  = ",Installation,Uninstallation"
oUdate = CreateObject("Microsoft.Update.Searcher")
nCnt = oUdate.GetTotalHistoryCount - 1
oHistory = oUdate.QueryHistory(0,nCnt)
udates=""
cFile=DirScript():"WinUpdates.txt"
ForEach h In oHistory
   udates=udates:"Title       : ":h.Title:@CRLF
   udates=udates:"Description : ":h.Description:@CRLF
   udates=udates:"Update ID   : ":h.UpdateIdentity.UpdateID:@CRLF
   udates=udates:"Revision    : ":h.UpdateIdentity.RevisionNumber:@CRLF
   udates=udates:"Support URL : ":h.SupportUrl:@CRLF
   udates=udates:"Date        : ":h.Date:@CRLF
   udates=udates:"Result      : ":ItemExtract(h.Operation+1,Operations,","):@CRLF
   udates=udates:" ":ItemExtract(h.ResultCode+1,ResultCodes,","):@CRLF:@CRLF
Next
oHistory  = 0
oUdate = 0
FilePut(cFile,udates)
Run("notepad.exe",cFile)
Exit

;/////////////////////////////////////////////////////////////////////////////////////////////////

Sample 2

;Winbatch 2009C Search for Software Updates
;               XP SP2
;
;Adapted from VBScript, but will generate WB error as
;some properties exceed WB variable length - see comments in udf
;
;UPDATE: 2/2/2010 - added install/uninstall udf
;
;Stan Littlefield: February 1, 2010
;////////////////////////////////////////////////////////////////////
GoSub udfs

;uncomment and test after running chkudates()
;goto test


cOut=DirScript():"winudates.txt"
If FileExist(cOut) Then FileDelete(cOut)
cTxt=""
chkudates()

;not the greatest way to display captured data
If FileExist(cOut) Then Run("notepad.exe",cOut)
Goto End

:test
uID="b4b9471c-1a5e-4d9c-94ef-84b00592946a"  ;net framework 1.1 should already be installed
ret=u_install(@TRUE,uID)
Message("",ret)


:End
Exit

:udfs
#DefineSubRoutine chkudates()
BoxOpen("Enumerating Windows Updates","Please Wait")

objSearcher = CreateObject("Microsoft.Update.Searcher")
objResults = objSearcher.Search("Type='Software'")
colUpdates = objResults.Updates

n=1

For i = 0 To colUpdates.Count - 1
    oItem=colUpdates.Item(i)
    cTitle=oItem.Title
    BoxText(cTitle)
    cTxt=cTxt:"Title: ":cTitle:@CRLF
    cTxt=cTxt:"Autoselect on Web sites: ":oItem.AutoSelectOnWebSites:@CRLF

    ForEach strUpdate In oItem.BundledUpdates
        cTxt=cTxt:"Bundled update: ":strUpdate:@CRLF
    Next
    cTxt=cTxt:"Can require source: ":oItem.CanRequireSource:@CRLF
    objCategories = oItem.Categories

    For z = 0 To objCategories.Count - 1
        cTxt=cTxt:"Category name: ":objCategories.Item(z).Name:@CRLF
        cTxt=cTxt:"Category ID: ":objCategories.Item(z).CategoryID:@CRLF
        ForEach strChild In objCategories.Item(z).Children
            cTxt=cTxt:"Child category: ":strChild:@CRLF
        Next
        cTxt=cTxt:"Category description: ":objCategories.Item(z).Description:@CRLF
        cTxt=cTxt:"Category order: ":objCategories.Item(z).Order:@CRLF
        cTxt=cTxt:"Category type: ":objCategories.Item(z).Type:@CRLF
    Next

    cTxt=cTxt:"Deadline: ":oItem.Deadline:@CRLF

    ;/////////////////////////////////////////////////////////////////////////////////////////////////////////
    ;Winbatch error - variable too long
    ;cTxt=cTxt:"Delta compressed content available: ":oItem.DeltaCompressedContentAvailable:@CRLF
    ;cTxt=cTxt:"Delta compressed content preferred: ":oItem.DeltaCompressedContentPreferred:@CRLF
    ;/////////////////////////////////////////////////////////////////////////////////////////////////////////

    cTxt=cTxt:"Description: ":oItem.Description:@CRLF
    cTxt=cTxt:"EULA accepted: ":oItem.EULAAccepted:@CRLF
    cTxt=cTxt:"EULA text: ":oItem.EULAText:@CRLF
    cTxt=cTxt:"Handler ID: ":oItem.HandlerID:@CRLF

    objIdentity = oItem.Identity
    cTxt=cTxt:"Revision number: ":objIdentity.RevisionNumber:@CRLF
    cTxt=cTxt:"Update ID: ":objIdentity.UpdateID:@CRLF

    objInstallationBehavior = oItem.InstallationBehavior
    cTxt=cTxt:"Can request user input: ":objInstallationBehavior.CanRequestUserInput:@CRLF
    cTxt=cTxt:"Impact: ":objInstallationBehavior.Impact:@CRLF
    cTxt=cTxt:"Reboot behavior: ":objInstallationBehavior.RebootBehavior:@CRLF
    cTxt=cTxt:"Requires network connectivity: ":objInstallationBehavior.RequiresNetworkConnectivity:@CRLF
    cTxt=cTxt:"Is beta: ":oItem.IsBeta:@CRLF
    cTxt=cTxt:"Is hidden: ":oItem.IsHidden:@CRLF
    cTxt=cTxt:"Is installed: ":oItem.IsInstalled:@CRLF
    cTxt=cTxt:"Is mandatory: ":oItem.IsMandatory:@CRLF
    cTxt=cTxt:"Is uninstallable: ":oItem.IsUninstallable:@CRLF

    ForEach strLanguage In oItem.Languages
        cTxt=cTxt:"Supported language: ":strLanguage:@CRLF
    Next

    cTxt=cTxt:"Last deployment change time: ":oItem.LastDeploymentChangeTime:@CRLF
    cTxt=cTxt:"Maximum download size: ":oItem.MaxDownloadSize:@CRLF
    cTxt=cTxt:"Minimum download size: ":oItem.MinDownloadSize:@CRLF
    cTxt=cTxt:"Microsoft Security Response Center severity: ":oItem.MsrcSeverity:@CRLF
    cTxt=cTxt:"Recommended CPU speed: ":oItem.RecommendedCPUSpeed:@CRLF
    cTxt=cTxt:"Recommended hard disk space: ":oItem.RecommendedHardDiskSpace:@CRLF
    cTxt=cTxt:"Recommended memory: ":oItem.RecommendedMemory:@CRLF
    cTxt=cTxt:"Release notes: ":oItem.ReleaseNotes:@CRLF
    cTxt=cTxt:"Support URL: ":oItem.SupportURL:@CRLF
    cTxt=cTxt:"Type: ":oItem.Type:@CRLF
    cTxt=cTxt:"Uninstallation notes: ":oItem.UninstallationNotes:@CRLF

    x = 1
    ForEach strStep In oItem.UninstallationSteps
        cTxt=cTxt:x:" -- ":strStep:@CRLF
        x = x + 1
    Next

    ForEach strArticle In oItem.KBArticleIDs
        cTxt=cTxt:"KB article: ":strArticle:@CRLF
    Next

    cTxt=cTxt:"Deployment action: ":oItem.DeploymentAction:@CRLF
    cTxt=cTxt:@CRLF:@CRLF
Next
oItem=0
objSearcher = 0
objResults = 0
colUpdates = 0
FilePut(cOut,cTxt)
BoxShut()
Return(1)
#EndSubRoutine

#DefineSubRoutine u_install(mode,id)
;////////////////////////////////////////////////////////////////
;mode:  1=install 0=uninstall
;id: the "Update ID" see the chkudates() udf should be a GUUD
;Returns: 3 items related to success of udf
;////////////////////////////////////////////////////////////////
retval=""
If mode
   BoxOpen("Installing %id%","Please Wait")
Else
   BoxOpen("Un-Installing %id%","Please Wait")
EndIf
objCollection = CreateObject("Microsoft.Update.UpdateColl")
objSearcher = CreateObject("Microsoft.Update.Searcher")
objResults = objSearcher.Search("UpdateID='%id%'")
colUpdates = objResults.Updates
objCollection.Add(colUpdates.Item(0))

objInstaller = CreateObject("Microsoft.Update.Installer")
objInstaller.Updates = objCollection
If mode
   objInstallResults = objInstaller.Install
Else
   objInstallResults = objInstaller.Uninstall
EndIf
If !mode Then retval=retval:objInstallResults.Exception:@CRLF
retval=retval:objInstallResults.RebootRequired:@CRLF
retval=retval:objInstallResults.ResultCode:@CRLF

;////////////////////////////////////
;result codes
;0 Not Started
;1 In Progress
;2 Succeeded
;3 Succeeded With Errors
;4 Failed
;5 Aborted
;////////////////////////////////////

objInstallResults=0
objInstaller=0
objResults=0
objSearcher=0
objCollection=0
BoxShut()
Return(retval)
#EndSubRoutine



Return



Article ID:   W17459
File Created: 2010:02:02:11:12:34
Last Updated: 2010:02:02:11:12:34