WUA IUpdate2.CopyToCache 抛出 WU_E_INVALID_UPDATE_TYPE

发布于 2024-12-17 03:13:37 字数 1523 浏览 0 评论 0原文

我在使 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

I have some problems getting the WUA API to run as expected.
I want to manually copy a update file to a machine and then feed it to the WUA.
The call IUpdate2.CopyToCache causes an error that confuses me slightly. The update is definitively correct. Using a file name that does not even exist also results in the same error!

There is another strange thing I noticed: I searched for an update and found it in the API, but writing it to disk does not work at all. The code executes and there is no error reported, but the directory stays empty.

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

Why is the CopyFromCache not doing anything and why is CopyToCache throwing this weird Exception, even if the file does not exist?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦上情书 2024-12-24 03:13:37

您的代码的问题在于指定的更新不是真正的更新。
它是一组更新的容器。尝试将文件复制到缓存以进行捆绑更新。

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

The problem with your code is that the specified update is not a real update.
It is a container for a bundle of updates. Try to copy the file to the cache for the bundled update.

    // 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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文