I am getting the error "Exception from HRESULT: 0x80240007" when I am trying to fetch the installed Windows updates. My code worked well in Windows 7, but it's not working in Windows XP. I am getting the error in the line var history = updateSearcher.QueryHistory(0, count);
This is my code snippet:
var updateSession = new UpdateSession();
var updateSearcher = updateSession.CreateUpdateSearcher();
var count = updateSearcher.GetTotalHistoryCount();
var history = updateSearcher.QueryHistory(0, count);
What changes do I need to make in the code?
0x80240007 is the error code WU_E_INVALIDINDEX as defined in wuerror.h:
// MessageId: WU_E_INVALIDINDEX
//
// MessageText:
//
// The index to a collection was invalid.
//
#define WU_E_INVALIDINDEX _HRESULT_TYPEDEF_(0x80240007L)
And the call to UpdateSession.CreateUpdateSearcher.QueryHistory
boils down to IUpdateSearcher::QueryHistory and its documentation says:
Remarks
This method returns WU_E_INVALIDINDEX if the startIndex parameter is less than 0 (zero) or if the Count parameter is less than or equal to 0 (zero).
count
is most likely not less than 0 but maybe ==0
You need something like
var count = updateSearcher.GetTotalHistoryCount();
var history = count > 0 ? updateSearcher.QueryHistory(0, count) : null;
(or a more complex case handling....)
User contributions licensed under CC BY-SA 3.0