0% found this document useful (0 votes)
104 views

Source Code

This VBScript script verifies installed updates on a Windows system. It first connects to the Windows Update API and queries for update history. It then outputs the host name, IP address, and installed update details to the screen and to a text file. A second script checks for available updates, allows the user to select which to install, downloads the selected updates, installs them, and will automatically reboot the system if needed.

Uploaded by

api-312996670
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

Source Code

This VBScript script verifies installed updates on a Windows system. It first connects to the Windows Update API and queries for update history. It then outputs the host name, IP address, and installed update details to the screen and to a text file. A second script checks for available updates, allows the user to select which to install, downloads the selected updates, installs them, and will automatically reboot the system if needed.

Uploaded by

api-312996670
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Source codes

Verifyinstalledupdates.vbs
' VBScript: verifyinstupd.vbs
' Modified by: Mariangely Torres
' Class: COMP230
' Professor: Elizabeth Gasko
'=================================
' Connect to the Windows Update COM object:
Set objSession = CreateObject("Microsoft.Update.Session")
Set objSearcher = objSession.CreateUpdateSearcher
intHistoryCount = objSearcher.GetTotalHistoryCount
' Get WU history data:
Set colHistory = objSearcher.QueryHistory(1, intHistoryCount)
'Get host name
set wshNetwork = WScript.CreateObject("WScript.Network")
strComputerName = wshNetwork.ComputerName
Wscript.Echo "Host Name: " & strComputerName
'Get host IP and MAC Addresses:
strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE
MACAddress > ''"
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems
= objWMIService.ExecQuery( strQuery, "WQL", 48 )
For Each objItem In colItems
If IsArray( objItem.IPAddress ) Then
If UBound( objItem.IPAddress ) = 0 Then
strIP = "IP Address: " & objItem.IPAddress(0)
Else
strIP = "IP Addresses: " & Join( objItem.IPAddress , " ")
End If
End If
Next
WScript.Echo strIP
'Create the file to copy results of output, delete and recreate if file exists:
set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists("C:\Scripts\Installed-Updates.txt") Then
FSO.DeleteFile "C:\Scripts\Installed-Updates.txt"
End If
set objTextFile = FSO.CreateTextFile("C:\Scripts\Installed-Updates.txt",WRITE)
' Review output on screen:
For Each objEntry in colHistory
WScript.Echo "=============================="
WScript.Echo objEntry.Title

WScript.Echo ""
WScript.Echo "Support URL: " & vbCrLf & objEntry.SupportURL
WScript.Echo ""
WScript.Echo "Description: " & vbCrLf & objEntry.Description
WScript.Echo ""
WScript.Echo "Date Installed: " & vbCrLf & objEntry.Date
WScript.Echo ""
Select Case objEntry.ResultCode
Case 1 ResultCode = "Pending Reboot"
Case 2 ResultCode = "Successfully Installed"
Case 4 ResultCode = "Installation Failed"
Case 5 ResultCode = "Installation Canceled"
Case Else
ResultCode = "Unknown Installation Status"
End Select
WScript.Echo "Results of Update: " & vbCrLf & ResultCode
WScript.Echo ""
WScript.Echo "Client application ID: " & vbCrLf & objEntry.ClientApplicationID
i=1
For Each strStep in objEntry.UninstallationSteps
WScript.Echo i & " -- " & strStep
i=i+1
Next
If objEntry.UninstallationNotes = "" Then
' No uninstallation notes, print nothing:
Else
WScript.Echo ""
WScript.Echo "Uninstallation notes: " & vbCrLf & objEntry.UninstallationNotes
End If
WScript.Echo "=============================="
WScript.Echo ""
WScript.Echo ""
'Write to text file the output of installed updates:
objTextFile.WriteLine "Host Name: " & strComputerName & vbCrlf & "IP
Address: " & strIP & vbCrlf & vbCrlf &_
"Title: " & objEntry.Title & vbCrlf & "Support URL: " &
objEntry.SupportURL & vbCrlf & _
"Description: " & objEntry.Description & vbCrlf & "Date Installed: " &
objEntry.Date & vbCrlf &_
"Results of Update: " & ResultCode & vbCrlf & "Client application ID: "
& objEntry.ClientApplicationID & vbCrlf &_
"Uninstallation notes: " & objEntry.UninstallationNotes & _
vbCrLf &
"=======================================================
===================================" & vbCrLf
Next
objTextFile.Close

ckdlinst.vbs
' VBScript: ckdlinst.vbs
' Modified by: Mariangely Torres
' Class: COMP230
' Professor: Elizabeth Gasko
'=================================
'***Script must be run as Administrator***
' Host Selection values
hsDefault = 0
hsManagedServer = 1
hsWindowsUpdate = 2
hsOthers
=3
'InStr values
intSearchStartChar = 1
dim strTitle
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
updateSearcher.ServerSelection = ssWindowsUpdate
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
WScript.Echo "List of available updates on host machine:"
For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
WScript.Echo I + 1 & "> " & update.Title
Next
If searchResult.Updates.Count = 0 Then
WScript.Echo "There are no available updates."
WScript.Quit
End If
WScript.Echo vbCRLF & "Creating collection of updates to download:"
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
addThisUpdate = false
If update.InstallationBehavior.CanRequestUserInput = true Then
WScript.Echo I + 1 & "> skipping: " & update.Title & _
" because it requires user input"
Else
If update.EulaAccepted = false Then
WScript.Echo I + 1 & "> note: " & update.Title & _
" has a license agreement that must be accepted:"

WScript.Echo update.EulaText
WScript.Echo "Do you accept this license agreement? (Y/N)"
''strInput = WScript.StdIn.ReadLine
strInput = "Y"
WScript.Echo
If (strInput = "Y" or strInput = "y") Then
update.AcceptEula()
addThisUpdate = true
Else
WScript.Echo I + 1 & "> skipping: " & update.Title & _
" because the license agreement was declined"
End If
Else
addThisUpdate = true
End If
End If
If addThisUpdate = true Then
WScript.Echo I + 1 & "> adding: " & update.Title
updatesToDownload.Add(update)
End If
Next
If updatesToDownload.Count = 0 Then
WScript.Echo "All applicable updates were skipped."
WScript.Quit
End If
WScript.Echo vbCRLF & "Downloading updates..."
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
rebootMayBeRequired = false
WScript.Echo vbCRLF & "Successfully downloaded updates:"
For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
WScript.Echo I + 1 & "> " & update.Title
updatesToInstall.Add(update)
If update.InstallationBehavior.RebootBehavior > 0 Then
rebootMayBeRequired = true
End If
End If
Next
If updatesToInstall.Count = 0 Then
WScript.Echo "No updates were successfully downloaded."
WScript.Quit
End If

If rebootMayBeRequired = true Then


WScript.Echo vbCRLF & "These updates may require a reboot."
End If
WScript.Echo vbCRLF & "Updates will automatically install" & vbCrLf

WScript.Echo "Installing updates..." &vbCrLf


Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
'Output results of install
WScript.Echo "Installation Results: " & _
installationResult.ResultCode &vbCrLf
WScript.Echo "Reboot will occur upon install completion if required: " & _
installationResult.RebootRequired & vbCRLF
WScript.Echo "Listing of updates installed " & _
"and individual installation results:"
For I = 0 to updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & _
updatesToInstall.Item(i).Title & _
": " & installationResult.GetUpdateResult(i).ResultCode
Next
If rebootmayberequired = True Then
WScript.Echo "PC will require a reboot for the updates to take affect." & _
"Reboot will occur in 60 seconds."
WScript.Sleep (60000)
Set OpSysSet = GetObject("winmgmts:
{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
Next
End If

You might also like