WUA IUpdate2.CopyToCache 抛出 WU_E_INVALID_UPDATE_TYPE
我在使 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码的问题在于指定的更新不是真正的更新。
它是一组更新的容器。尝试将文件复制到缓存以进行捆绑更新。
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.