2013-09-24 79 views
7

正在从本地服务器下载更新,而不是从WUS或Microsoft存储库下载更新。本地服务器是基于Linux的,哪个主机是每个更新的内容。WUApiLib IUpdateInstaller2产生错误;某些操作系统更新安装了其他操作系统-2145124318

我没有使用UpdateDownloader从Microsoft Servers下载,我手动下载更新内容,然后使用CopyToCache

这些安装罚款

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

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

这些并没有

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

更新适用于Windows XP的Microsoft .NET Framework 3.5 SP1,服务器2003,Vista和Server 2008年86(KB2836940)

我的过程是如何工作的

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

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

随着中说,问题是,某些更新安装完全正常,但某些更新(我认为有一个以上的bundle-updates的那些)别不要穿过它,它让我发疯!

我首先下载每个Uri,然后将它们加载到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方法通过如下图所示:

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

的更新安装就好了,如果我在执行其手动双击并手动安装,而不使用码。

+2

是一个互动的环境中运行你的代码?通常这些事情都会留下相当详细的日志,而不仅仅是一个'-2145124318'的返回码。此外,Google的一个快速版本[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)这可能表明更新无法连接到互联网?无论是因为BITS,代理设置还是其他原因。 –

+0

@ ta.speot.is http://paste.ofcode.org/tzXzURmFHvLRNpYFpiekFG我在VS2010中以调试模式运行它。我已经在XP和Windows 7上测试过了。文件通过“CopyToCache”被推送到'IUpdate',我无法从Microsoft服务器获取'WUapi'。另外,我有AU禁用。 – Dayan

+0

那么失败的更新似乎与Windows Defender有关。请参阅http://support.microsoft.com/kb/918355,其中引用0x80240022。它说,尝试使用方法2来安装更新,基本上“这太难了,手动安装”。有一个错误提示[在这里](http://www.hanselman.com/blog/WindowsDefenderErrors0x8024402c0x80240022And1609.aspx),但不是不太可能,说明已过时... –

回答

2

看起来WUApi曝光IUpdate其中持有bundleUpdates多个级别。之前,我只是简单地检索bundleUpdates的最高级别,通过这样做,由于缺少更新所需的内容而使某些更新失败;大多数Windows更新有多个级别的捆绑包。

例如,想象一下这棵树状结构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中的字典密钥类型“bundleName”和list of value将保存该特定包的所有URI。

像这样:

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

你在做什么与捆绑清单标题和uris?你是否打电话来下载每一个? –

+0

@inquisitor是的,它会被填充并发送到本地服务器,该服务器将下载这些包并将它们保留给我。一旦需要,我将检索更新并通过相应地提供所有软件包更新进行安装。 – Dayan

相关问题