本文介绍了WUApiLib IUpdateInstaller2产生的错误;一些操作系统的更新安装别人扔的HResult -2145124318的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新正在从本地服务器上下载,而不是从WUS或Microsoft系统信息库。本地服务器是基于其主机的内容对每个更新的Linux。

我不使用 UpdateDownloader 从微软服务器上下载,我手动下载更新内容,然后使用 CopyToCache

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

这些安装罚款

对于Microsoft .NET Framework 3.5 SP1的Windows XP,Server 2003安全更新,Vista中,Server 2008中的x86(KB2736416)

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

微软的Visual Studio 2010(KB2542054)安全更新

Security Update for Microsoft Visual Studio 2010 (KB2542054)

这些并没有

对于Microsoft .NET Framework 4的XP,Server 2003安全更新,  Vista中,Windows 7,Server 2008中的x86(KB2840628)

更新的Microsoft .NET Framework 3.5 SP1的Windows XP,Server 2003中,Vista和Server 2008中的x86(KB2836940)

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

如何处理我的作品

我收到这个从我用它来下载所有下载内容进行更新的本地服务器的安装。 (以上KB2840628的块引用文本是下面提供的例子)

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)"
}

随着中说,问题是,一些更新安装完全正常,但某些更新(我相信那些有超过1束更新)不走通,其快把我逼疯了!

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

我先下载每个开放的,然后加载它们与更新 CopyToCache

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;
  }

在此,返回的集合是通过我的 WindowsUpdateInstaller 方法通过如下图所示:

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);

更新安装就好了,如果我手动双击可执行文件,并手动安装,而不使用code。

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

推荐答案

我写了这一篇博客文章而进入更详细一点。 http://ddelapaz.github.io

I wrote a blog post on this which goes into a bit more detail.http://ddelapaz.github.io

看来, WUApi 自曝 IUpdate 持有多层次 bundleUpdates 。以前,我只是检索的顶级 bundleUpdates 它这样做,取得了一定的更新失败归因于缺少的更新要求的内容;大多数Windows更新包有超过1级。

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.

例如,假设此树状结构1更新(又名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

我的解决方案是创建一个递归函数来单独分析每个更新,并保持所有的URI的键式字典束名称名单值 s表示将保留所有的URI为特定包。

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.

像这样:

Dictionary<string, List<string>>

递归函数如下:

 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;
        }

这篇关于WUApiLib IUpdateInstaller2产生的错误;一些操作系统的更新安装别人扔的HResult -2145124318的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:00