我正试图在多台不同的机器上收集Windows更新的准确图片,特别是KB安装。我尝试了一些分散在其中的不同的代码片段,但我似乎仍然无法准确地描述所安装的代码。准确地说,我的意思是,当我使用Windows在机器上检查时,我收集到的似乎是一个子集!好像搞不清这事!
以下是我尝试过的几件事;
UpdateSession uSession = new UpdateSession();
IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
uSearcher.Online = false;
ISearchResult sResult = uSearcher.Search("IsInstalled=1");
foreach (IUpdate update in sResult.Updates)
{
foreach (string kbaid in update.KBArticleIDs)
{
txtAllUpdates.AppendText(kbaid + Environment.NewLine);
}
}
我还尝试在这个例程中添加代码来收集绑定更新字段中的所有更新,如下所示;
foreach (IUpdate update2 in update.BundledUpdates)
{
txtAllUpdates.AppendText("\t--> " + update2.Title + Environment.NewLine);
foreach (string kbaid2 in update2.BundledUpdates)
{
string kbNo = GetKBNo(update2.Title.ToLower());
txtAllUpdates.AppendText("\t\t" + kbNo);
}
}
我也尝试过查看更新历史,但这为我提供了另一组数据--仍然不完整!
UpdateSession updateSession = new UpdateSession();
IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher();
int count = updateSearcher.GetTotalHistoryCount();
MessageBox.Show("Total Count = " + count);
IUpdateHistoryEntryCollection history = updateSearcher.QueryHistory(0, count);
for (int i = 0; i < count; ++i)
{
txtAllUpdates.AppendText("\t\t\t" + history[i].Title);
}
我还检查了一些利用注册表的代码,但据我所读,这不是正确的做法。此时,我正在执行许多不同的查询,搜索"KB“引用的条目,构建一个列表并删除重复项,但我仍然没有得到屏幕上看到的相同的列表!即使这确实有效,也不可能是正确的方法--我觉得我一定是错过了什么。
最后,我试着获取关于上次检查和安装更新的时间的信息--即使这与显示的内容不匹配。我用下面的代码完成了这个操作;
var auc = new AutomaticUpdatesClass();
DateTime? lastInstallationSuccessDateUtc = null;
if (auc.Results.LastInstallationSuccessDate is DateTime)
lastInstallationSuccessDateUtc = new DateTime(((DateTime)auc.Results.LastInstallationSuccessDate).Ticks, DateTimeKind.Utc);
DateTime? lastSearchSuccessDateUtc = null;
if (auc.Results.LastSearchSuccessDate is DateTime)
lastSearchSuccessDateUtc = new DateTime(((DateTime)auc.Results.LastSearchSuccessDate).Ticks, DateTimeKind.Utc);
lblInstall.Text += lastInstallationSuccessDateUtc.ToString();
lblSearch.Text += lastSearchSuccessDateUtc.ToString();
有人在这方面有专长吗?真的想把这件事做好!
谢谢你抽出时间阅读!
尊敬的马歇尔
发布于 2022-08-04 14:27:40
查找已安装软件的所有方法都是不完整的,因此我在Get-KbInstalledUpdate中使用了多种方法,我将其描述为:
替换Get-Hotfix、Get-Package、搜索注册表和搜索CIM以获得更新。
虽然我没有尝试过这边请,但本质上是:
$session = New-Object -ComObject "Microsoft.Update.Session"
$updatesearcher = $session.CreateUpdateSearcher()
$count = $updatesearcher.GetTotalHistoryCount()
$updates = $updatesearcher.QueryHistory(0, $count)
https://stackoverflow.com/questions/45331447
复制相似问题