If you have an off-line machine that you want to check for Windows Updates I have devised a script that will do just that.
Simply run this script on a machine that has Internet connectivity. Comment out the SaveBinaryFile bit and copy the script and the file it has downloaded to another computer and run.
Simply run this script on a machine that has Internet connectivity. Comment out the SaveBinaryFile bit and copy the script and the file it has downloaded to another computer and run.
Option Explicit
'-- Get Working Directory --'
Dim WShell, CurrentDirectory
Set WShell = CreateObject("WScript.Shell")
'Just use the script's folder: CurrentDirectory = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
CurrentDirectory = WShell.CurrentDirectory & "\"
WScript.Echo "Current Directory - " & CurrentDirectory
Set WShell = Nothing
'-- Inform the user. --'
WScript.Echo "Downloading list of updates..." & VbCrlf
'-- Download the latest list of updates--'
SaveBinaryFile "http://go.microsoft.com/fwlink/?LinkId=76054", "Wsusscn2.cab"
'-- Now we can check our system --'
Dim UpdateSession, UpdateServiceManager, UpdateService, UpdateSearcher
Set UpdateSession = CreateObject("Microsoft.Update.Session")
Set UpdateServiceManager = CreateObject("Microsoft.Update.ServiceManager")
'-- Offline catalog (Wsusscn2.cab). This is the offline catalog file. --'
On Error Resume Next
Set UpdateService = UpdateServiceManager.AddScanPackageService("Offline Sync Service", CurrentDirectory & "wsusscn2.cab")
If Err.Number = 5 Then
WScript.Echo "Error: " & Err.Number & " - " & Err.Description & VbCrlf
On Error GoTo 0
WScript.Echo "Reason: The API is unable to use a network path for the catalog file. The path specified was " & CurrentDirectory & "wsusscn2.cab. Please move this to a local path and try again." & VbCrlf
WScript.Quit
ElseIf Err.Number <> 0 Then
'-- Store the current error --'
Dim Number
Dim Source
Dim Description
Dim HelpFile
Dim HelpContext
Number = Err.Number
Source = Err.Source
Description = Err.Description
HelpFile = Err.HelpFile
HelpContext = Err.HelpContext
On Error Goto 0
'-- Re-raise Error --'
Err.Raise Number, Source, Description, HelpFile, HelpContext
End If
On Error GoTo 0
'-- Now create a searcher based on our Microsoft Update Session. --'
Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()
'-- Inform the user. --'
WScript.Echo "Searching for updates..." & vbCRLF
'-- Link our API to the real Windows Update service --'
UpdateSearcher.ServerSelection = 3 ' ssOthers
UpdateSearcher.ServiceID = UpdateService.ServiceID
Dim SearchResult
Set SearchResult = UpdateSearcher.Search("IsInstalled=0")
Dim Updates
Set Updates = SearchResult.Updates
If searchResult.Updates.Count = 0 Then
WScript.Echo "There are no applicable updates."
WScript.Quit
End If
WScript.Echo "List of applicable items on the machine when using wsusscn2.cab:" & vbCRLF
Dim Count
For Count = 0 To searchResult.Updates.Count-1
Dim Update
Set Update = searchResult.Updates.Item(Count)
WScript.Echo Count + 1 & "> " & update.Title
Set Update = Nothing
Next
Set Updates = Nothing
Set SearchResult = Nothing
Set UpdateSearcher = Nothing
Set UpdateSession = Nothing
WScript.Quit
Sub SaveBinaryFile(strFileURL,strHDLocation)
Dim FSO
Set FSO = Createobject("Scripting.FileSystemObject")
If NOT FSO.FileExists(strHDLocation) Then
'FSO.DeleteFile strHDLocation
Dim XMLHTTP
Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
XMLHTTP.open "GET", strFileURL, false
XMLHTTP.send()
If XMLHTTP.Status = 200 Then
Dim ADOStream
Set ADOStream = CreateObject("ADODB.Stream")
ADOStream.Open
ADOStream.Type = 1 'adTypeBinary
ADOStream.Write XMLHTTP.ResponseBody
ADOStream.Position = 0 'Set the stream position to the start
End If
ADOStream.SaveToFile strHDLocation
ADOStream.Close
Set ADOStream = Nothing
End If
Set XMLHTTP = Nothing
Set FSO = Nothing
End Sub
'-- Get Working Directory --'
Dim WShell, CurrentDirectory
Set WShell = CreateObject("WScript.Shell")
'Just use the script's folder: CurrentDirectory = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
CurrentDirectory = WShell.CurrentDirectory & "\"
WScript.Echo "Current Directory - " & CurrentDirectory
Set WShell = Nothing
'-- Inform the user. --'
WScript.Echo "Downloading list of updates..." & VbCrlf
'-- Download the latest list of updates--'
SaveBinaryFile "http://go.microsoft.com/fwlink/?LinkId=76054", "Wsusscn2.cab"
'-- Now we can check our system --'
Dim UpdateSession, UpdateServiceManager, UpdateService, UpdateSearcher
Set UpdateSession = CreateObject("Microsoft.Update.Session")
Set UpdateServiceManager = CreateObject("Microsoft.Update.ServiceManager")
'-- Offline catalog (Wsusscn2.cab). This is the offline catalog file. --'
On Error Resume Next
Set UpdateService = UpdateServiceManager.AddScanPackageService("Offline Sync Service", CurrentDirectory & "wsusscn2.cab")
If Err.Number = 5 Then
WScript.Echo "Error: " & Err.Number & " - " & Err.Description & VbCrlf
On Error GoTo 0
WScript.Echo "Reason: The API is unable to use a network path for the catalog file. The path specified was " & CurrentDirectory & "wsusscn2.cab. Please move this to a local path and try again." & VbCrlf
WScript.Quit
ElseIf Err.Number <> 0 Then
'-- Store the current error --'
Dim Number
Dim Source
Dim Description
Dim HelpFile
Dim HelpContext
Number = Err.Number
Source = Err.Source
Description = Err.Description
HelpFile = Err.HelpFile
HelpContext = Err.HelpContext
On Error Goto 0
'-- Re-raise Error --'
Err.Raise Number, Source, Description, HelpFile, HelpContext
End If
On Error GoTo 0
'-- Now create a searcher based on our Microsoft Update Session. --'
Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()
'-- Inform the user. --'
WScript.Echo "Searching for updates..." & vbCRLF
'-- Link our API to the real Windows Update service --'
UpdateSearcher.ServerSelection = 3 ' ssOthers
UpdateSearcher.ServiceID = UpdateService.ServiceID
Dim SearchResult
Set SearchResult = UpdateSearcher.Search("IsInstalled=0")
Dim Updates
Set Updates = SearchResult.Updates
If searchResult.Updates.Count = 0 Then
WScript.Echo "There are no applicable updates."
WScript.Quit
End If
WScript.Echo "List of applicable items on the machine when using wsusscn2.cab:" & vbCRLF
Dim Count
For Count = 0 To searchResult.Updates.Count-1
Dim Update
Set Update = searchResult.Updates.Item(Count)
WScript.Echo Count + 1 & "> " & update.Title
Set Update = Nothing
Next
Set Updates = Nothing
Set SearchResult = Nothing
Set UpdateSearcher = Nothing
Set UpdateSession = Nothing
WScript.Quit
Sub SaveBinaryFile(strFileURL,strHDLocation)
Dim FSO
Set FSO = Createobject("Scripting.FileSystemObject")
If NOT FSO.FileExists(strHDLocation) Then
'FSO.DeleteFile strHDLocation
Dim XMLHTTP
Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
XMLHTTP.open "GET", strFileURL, false
XMLHTTP.send()
If XMLHTTP.Status = 200 Then
Dim ADOStream
Set ADOStream = CreateObject("ADODB.Stream")
ADOStream.Open
ADOStream.Type = 1 'adTypeBinary
ADOStream.Write XMLHTTP.ResponseBody
ADOStream.Position = 0 'Set the stream position to the start
End If
ADOStream.SaveToFile strHDLocation
ADOStream.Close
Set ADOStream = Nothing
End If
Set XMLHTTP = Nothing
Set FSO = Nothing
End Sub
Matthew1471's ASP 


