当我试图获取安装的Windows更新时,我得到了错误"Exception from HRESULT: 0x80240007“。我的代码在Windows 7中运行良好,但在Windows中不起作用。我得到了行var history = updateSearcher.QueryHistory(0, count);
中的错误
这是我的代码片段:
var updateSession = new UpdateSession();
var updateSearcher = updateSession.CreateUpdateSearcher();
var count = updateSearcher.GetTotalHistoryCount();
var history = updateSearcher.QueryHistory(0, count);
我需要在代码中做哪些修改?
发布于 2012-11-08 10:08:28
0x80240007是在wuerror.h中定义的错误代码WU_E_INVALIDINDEX:
// MessageId: WU_E_INVALIDINDEX
//
// MessageText:
//
// The index to a collection was invalid.
//
#define WU_E_INVALIDINDEX _HRESULT_TYPEDEF_(0x80240007L)
对UpdateSession.CreateUpdateSearcher.QueryHistory
的调用可以归结为IUpdateSearcher::QueryHistory及其文档:
备注 如果WU_E_INVALIDINDEX参数小于0(零),或者计数参数小于或等于0(零),则此方法返回startIndex。
count
最有可能不小于0,但可能是==0
你需要这样的东西
var count = updateSearcher.GetTotalHistoryCount();
var history = count > 0 ? updateSearcher.QueryHistory(0, count) : null;
(或更复杂的案件处理.)
https://stackoverflow.com/questions/13286577
复制相似问题