【发布时间】:2011-11-21 10:38:58
【问题描述】:
让 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
【问题讨论】: