Python调用get_windows_updates查询Windows更新触发com_error如何解决
报错根因
错误码-2145120257对应Windows Update Agent官方错误码WU_E_NO_SERVICE,触发原因是Windows更新相关服务未正常运行,或者本地更新缓存损坏,导致COM接口无法读取系统更新记录。
解决方案
- 检查Windows更新服务状态
按Win+R输入services.msc回车打开服务管理器,找到以下3个服务,确认状态为「正在运行」,启动类型设置为「自动」:- Windows Update
- Background Intelligent Transfer Service (BITS)
- Cryptographic Services
- 重置Windows更新组件
以管理员身份运行命令提示符,依次执行以下命令,完成后重启设备再重试代码:net stop wuauserv net stop cryptSvc net stop bits net stop msiserver ren C:\Windows\SoftwareDistribution SoftwareDistribution.old ren C:\Windows\System32\catroot2 catroot2.old net start wuauserv net start cryptSvc net start bits net start msiserver - 调整接口调用参数
调用函数时增加过滤参数,跳过异常的更新条目:get_windows_updates(filter_duplicates=True, include_all=False) - 调整依赖包版本
当前版本的windows-tools对异常COM返回值处理有缺陷,可执行命令安装兼容版本:pip install windows-tools==2.10.0
内容的提问来源于stack exchange,提问作者sodmzs1
相关产品推荐
相关产品推荐

