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
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);
User contributions licensed under CC BY-SA 3.0