7

Updates are being downloaded from a local server and not from WUS or Microsoft Repositories. Local server is Linux based which host's the contents for each update.

I'm not using UpdateDownloader to download from Microsoft Servers, i manually download the update content and then use CopyToCache.

These installed fine

Security Update for Microsoft .NET Framework 3.5 SP1 on Windows XP, Server 2003, Vista, Server 2008 x86 (KB2736416)

Security Update for Microsoft Visual Studio 2010 (KB2542054)

These Didn't

Security Update for Microsoft .NET Framework 4 on XP, Server 2003, Vista, Windows 7, Server 2008 x86 (KB2840628)

Update for Microsoft .NET Framework 3.5 SP1 on Windows XP, Server 2003, Vista and Server 2008 x86 (KB2836940)

How my process works

I receive this for an install from a local server which i use to download all download content for the update. (The blockquote text above KB2840628 is the example provided below)

{
  "app_uris": [
    {
      "file_name": "msipatchregfix-x86_94a84b80b8b45a1ac53a0e5d085513da0f099655.exe",
      "file_uri": "https://192.168.5.108/packages/d13c13c81f94fbb48f39c817a71ff239a31773d3a0e821a968dc42a913892841/msipatchregfix-x86_94a84b80b8b45a1ac53a0e5d085513da0f099655.exe",
      "file_size": 130600
    },
    {
      "file_name": "ndp40-kb2840628-v2-x86_891d50ff3c1322db3fb0fde222ebb0aaa5260272.exe",
      "file_uri": "https://192.168.5.108/packages/d13c13c81f94fbb48f39c817a71ff239a31773d3a0e821a968dc42a913892841/ndp40-kb2840628-v2-x86_891d50ff3c1322db3fb0fde222ebb0aaa5260272.exe",
      "file_size": 13294216
    }
  ],
  "app_id": "d13c13c81f94fbb48f39c817a71ff239a31773d3a0e821a968dc42a913892841",
  "app_name": "Security Update for Microsoft .NET Framework 4 on XP, Server 2003, Vista, Windows 7, Server 2008 x86 (KB2840628)"
}

With that said, the problem is that some updates install perfectly fine, but certain updates (I believe the ones that have more than one bundle-updates) don't go thru, its driving me mad!

I first download each Uri and then load them into the update with CopyToCache.

  var collection = new UpdateCollection();
  IList<string> updateFiles = Directory.GetFiles(updateFolder);
  var fileCollection = new StringCollection();

  try
  {
       foreach (var file in updateFiles)
               fileCollection.Add(file);

       //Error happens here on certain updates. Not all.
       ((IUpdate2)update.BundledUpdates[0]).CopyToCache(fileCollection);
       collection.Add(update);
       return collection;
  }
  catch (Exception e)
  {
     return null;
  }

After this, the returned collection is passed through my WindowsUpdateInstaller Method shown below:

IUpdateSession Session = new UpdateSession();
var updatesToInstall = //THIS GETS THE RETURN FROM THE ABOVE CODE...
var installer        = (IUpdateInstaller2)Session.CreateUpdateInstaller();

installer.ForceQuiet         = true;
installer.AllowSourcePrompts = false;
installer.Updates            = updatesToInstall;

foreach (IUpdate updateNode in installer.Updates)
{
   updateNode.AcceptEula();
}

//FAILS HERE WITH "-2145124318, Result code: orcFailed",
var installationRes = installer.Install(); 
var installResult   = installationRes.GetUpdateResult(0);

The update installs just fine if i manually double click on the executable it and install it manually without using the code.

Dayan
  • 7,634
  • 11
  • 49
  • 76
  • 2
    Is your code running in an interactive environment? And usually these sorts of things leave fairly detailed logs, more than just a `-2145124318` return code. Also, a quick Google yielded [this](http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_update/windows-update-will-not-work-getting-error/500d9cbb-d394-4f3b-ac32-88ad46414d2a) which might suggest the updates can't connect to the internet? Either because of BITS, proxy settings or otherwise. – ta.speot.is Sep 27 '13 at 02:18
  • @ta.speot.is http://paste.ofcode.org/tzXzURmFHvLRNpYFpiekFG I tested running it in debug mode in VS2010. I've tested it on XP, Windows 7. Files are being pushed to the `IUpdate` via `CopyToCache`, i can't have `WUapi` fetch it from Microsoft servers. Also, i have AU Disabled. – Dayan Sep 27 '13 at 02:53
  • Well the failing update seems to be something related to Windows Defender. See http://support.microsoft.com/kb/918355, which refers to 0x80240022. It says to try using Method 2 to install the update which is basically "it's all too hard, install it manually". There's a reference to the error [over here](http://www.hanselman.com/blog/WindowsDefenderErrors0x8024402c0x80240022And1609.aspx) but not unlikely that the instructions are out of date... – ta.speot.is Sep 27 '13 at 04:58

1 Answers1

3

It appears that the WUApi exposes IUpdate which holds multiple levels of bundleUpdates. Before, I was simply retrieving the top level of bundleUpdates which by doing so, made certain updates fail due to missing content required by the update; most windows updates have more than 1 level of bundles.

For example, imagine this tree like structure for 1 Update (aka IUpdate):

Update 1
    ---> Bundle 1
       *URL 1
       *URL 2
         ----> Bundle 1A
               *URL 1
               *URL 2
               *URL 3

    ---> Bundle 2
       *URL 1
         ----> Bundle 2A
               *URL 1
               *URL 2
         ----> Bundle 2B
               *URL 1

   ----> Bundle 3
         *URL 1
          ----> Bundle 3A
                *URL 1
                *URL 2

My Solution was to create a Recursive function to parse each update individually and keep all URIs in a dictionary of key type "bundleName" and list of values that will hold all URIs for that particular bundle.

Like So:

Dictionary<string, List<string>>

The Recursive function is the following:

 private static Dictionary<string, List<string>> GetAllUpdates(IUpdate iUpdate)
        {
            var bundleDict = new Dictionary<string, List<string>>();

            foreach (IUpdate bundle in iUpdate.BundledUpdates)
            {
                foreach (IUpdateDownloadContent udc in bundle.DownloadContents)
                {
                    var downloadContents = new List<string>();
                    if (String.IsNullOrEmpty(udc.DownloadUrl))
                        continue;

                    var url = udc.DownloadUrl;
                    downloadContents.Add(url);

                    if (!bundleDict.ContainsKey(bundle.Title))   
                        bundleDict.Add(bundle.Title, downloadContents);
                }

                if (bundle.BundledUpdates.Count > 0)
                {
                    var valuesReturned = GetAllUpdates(bundle);
                    foreach (var data in valuesReturned)
                    {
                      if(!bundleDict.ContainsKey(data.Key))     
                         bundleDict.Add(data.Key, data.Value);
                    }

                }
            }

            return bundleDict;
        }
Dayan
  • 7,634
  • 11
  • 49
  • 76
  • what were you doing with the list of bundled titles and uris? Were you calling something to download each one? – nullByteMe Oct 08 '13 at 14:36
  • @inquisitor yeah, it gets populated and sent out to a local server that will download those packages and keep them for me. Once needed, i will retrieve the update and install it by providing all the bundle updates accordingly. – Dayan Oct 09 '13 at 00:53
  • Hello, did you manage to get download links for windows 10 feature updates as well ? It seems line wuapi doesn't provide download urls for feature updates. Could you please confirm if you have same situation ? – Cozdemir Jul 23 '21 at 17:51
  • @Cozdemir Its been a very long time since i touched any windows update code, sorry! I will see if i can get my hands on that codebase again later today and get back to you. – Dayan Aug 03 '21 at 14:17
  • It would be very nice. Thank you so much. I did some research and confirmed that wsus server has all this links for windows updates but when you query updates via wuapi there are no links for feature updates. – Cozdemir Aug 04 '21 at 11:50