WUA IUpdate2.CopyToCache throws WU_E_INVALID_UPDATE_TYPE

本文关键字:INVALID UPDATE TYPE WU IUpdate2 CopyToCache throws WUA | 更新日期: 2023-09-27 18:15:14

我在使WUA API按预期运行方面遇到了一些问题。我想手动将更新文件复制到机器上,然后将其提供给WUA。调用IUpdate2。CopyToCache会导致一个让我有点困惑的错误。这个更新绝对是正确的。使用甚至不存在的文件名也会导致相同的错误!

我注意到另一件奇怪的事情:我搜索了一个更新,并在API中找到了它,但是将它写入磁盘根本不起作用。代码执行,没有错误报告,但是目录仍然为空。

IUpdateSearcher updateSearcher = new UpdateSearcher();
updateSearcher.Online = true;
ISearchResult searchResult = updateSearcher.Search("UpdateID='" + wsusID + "'");
if (searchResult.ResultCode == OperationResultCode.orcSucceeded && searchResult.Updates.Count == 1)
{
  IUpdate update = searchResult.Updates[0];
  Console.WriteLine(update.KBArticleIDs[0]);
  Console.WriteLine(update.Title);
  Console.WriteLine(update.Identity.UpdateID);
  Console.WriteLine("IsInstalled=" + update.IsInstalled);
  Console.WriteLine("IsDownloaded=" + update.IsDownloaded);
  // this line does nothing                  
  update.CopyFromCache("C:''Test''", true);
  // this returns error code 0
  int errorCode = Marshal.GetLastWin32Error();
  var update2 = (IUpdate2)update;
  var s = new StringCollection();
  // this file has been manually downloaded and exists!
  s.Add(@"C:'test'Windows6.1-KB2518869-x64.msu");
  // this throws the exception (0x80240026 - WU_E_INVALID_UPDATE_TYPE)
  update2.CopyToCache(s);
}

为什么CopyFromCache不做任何事情,为什么CopyToCache抛出这个奇怪的异常,即使文件不存在?

API参考:http://msdn.microsoft.com/en-us/library/windows/desktop/aa386101(v=VS.85).aspx

WUA IUpdate2.CopyToCache throws WU_E_INVALID_UPDATE_TYPE

代码的问题是指定的更新不是真正的更新。它是一个更新包的容器。尝试将文件复制到打包更新的缓存中。

    // Example
    Console.WriteLine("Bundled update=" + update.BundledUpdates[0].Title);
   var s = new StringCollection();
   s.Add(@"C:'test'Windows6.1-KB2518869-x64.msu");
   ((IUpdate2)update.BundledUpdates[0]).CopyToCache(s);