Reputation: 11
I am looking for some help with automating the installation of Windows Updates by using the wsusscn2.cab file available from the Microsoft website.
The setup I am trying to implement this onto is a bit of a strange one which is why I think I cannot find much help using Google.
I have 8 machines running Windows 7 SP1 that cannot be connected to the internet, therefore I am downloading the wsusscn2.cab file from Microsoft which apparently contains a list of all updates released and the actual update/hotfixes themselves.
The code I have so far is allowing me to use WUApiLib to read the .cab file and establish from it, which updates are not installed on the machine. This is currently returning a list of around 149 updates that are available but not installed.
When checking the .IsDownloaded() function of each update/hotfix, it is returning False and the Error Code is 'orcFailed'.
This is as close as I can get, as I said with the setup I have, Google is not providing me with alot of help as most people are mentioning things like WSUS on a Windows Server which is not possible or other online solutions which is also something I cannot do.
Here is a snippet of the code I have so far, I'm new to this library and this is my first major C# project so any help would be much appreciated as I feel I'm hitting a brick wall at the minute. Could someone also confirm if the updates are actually stored in the .cab file as I have tried extracting them to see whats inside, to no avail?
Many thanks!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WUApiLib;
using System.Management;
using Shell32;
namespace SoftwareUpdateTool
{
class InstallUpdates
{
public static void Getupdates()
{
UpdateSession updateSession = new UpdateSession();
UpdateServiceManager updateSM = new UpdateServiceManager();
IUpdateService updateService = updateSM.AddScanPackageService("Offline Sync Service", "C:\\Users\\Admin\\Desktop\\Windows Updates\\wsusscn2.cab");
IUpdateSearcher searcher = updateSession.CreateUpdateSearcher();
IUpdateInstaller installer = updateSession.CreateUpdateInstaller();
searcher.ServerSelection = ServerSelection.ssOthers;
searcher.ServiceID = updateService.ServiceID;
ISearchResult SearchResults = searcher.Search("IsInstalled=0");
UpdateCollection foundUpdates = SearchResults.Updates;
Console.WriteLine("Number of updates found are " + foundUpdates.Count);
installer.Updates = foundUpdates;
int updateCount = 0;
foreach (IUpdate x in foundUpdates)
{
Console.WriteLine(x.Title + " " + x.IsDownloaded.ToString());
Console.WriteLine("Error Code >> " + ConvertCode(installResult.GetUpdateResult(updateCount).ResultCode.ToString()));
updateCount += 1;
}
}
private static string ConvertCode(string errorCode)
{
switch (errorCode)
{
case "0":
errorCode = errorCode + " not started";
break;
case "1":
errorCode = errorCode + " in progress";
break;
case "2":
errorCode = errorCode + " succeeded";
break;
case "3":
errorCode = errorCode + " suceeded with errors";
break;
case "4":
errorCode = errorCode + " failed";
break;
case "5":
errorCode = errorCode + " aborted";
break;
}
return errorCode;
}
}
}
Upvotes: 1
Views: 3144
Reputation: 31
It could be possible you aren't downloading the updates from the .cab file before installing. When downloading updates through the web I've used something like.
`/// <summary>
/// Downloads list up updates or update
/// </summary>
/// <param Update Collection="uCollection"></param>
public void Download(UpdateCollection uCollection)
{
//creates new Downloader
UpdateDownloader uDownloader = new UpdateDownloader();
//Sets Downloader updates
uDownloader.Updates = uCollection;
//Downloads the updates
uDownloader.Download();
}`
You need to check if they are downloaded then try running the installer
EDIT
From: https://msdn.microsoft.com/en-us/library/windows/desktop/aa387290(v=vs.85).aspx
The Wsusscn2.cab file is a cabinet file that is signed by Microsoft. This file contains info about security-related updates that are published by Microsoft. Computers that aren't connected to the Internet can be scanned to see whether these security-related updates are present or required. The Wsusscn2.cab file doesn't contain the security updates themselves so you must obtain and install any needed security-related updates through other means. New versions of the Wsusscn2.cab file are released periodically as security-related updates are released, removed, or revised on the Windows Update site.
Wsusscn2.cab doesn't contain the actual updates its just used for scanning. You would need to download all those updates then run the installer against the updates you downloaded. You can use something like http://download.wsusoffline.net/ to help you get the updates.
Upvotes: 2