我正在寻找一种从工作站或服务器(Microsoft Windows)获取所有更新的方法。
当我查看控制面板→程序→程序和功能→已安装的更新时,我还可以看到Visual Studio和其他产品的更新。
示例:
Visual Studio 2015 Update 3 (KB3022398) Update for Microsoft Visual Studio 2015 (KB3165756)
但是我尝试过的所有编程方法都没有让我获得Visual Studio的更新。我怎么能做到这一点?
我试过了:
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Updates = $Searcher.QueryHistory(0,$HistoryCount)
$Updates | Select Title, @{l='Name';e={$($_.Categories).Name}}, Date | ft
Get-HotFix
Get-WmiObject -Class "Win32_QuickfixEngineering"
如何以编程方式获取所有更新的任何帮助都将非常感激。
答案 0 :(得分:1)
如果您使用的是C#,则可以使用WUApiLib
Type t = Type.GetTypeFromProgID("Microsoft.Update.Session",
UpdateSession UpdateSession = (UpdateSession)Activator.CreateInstance(
IUpdateSearcher UpdateSearchResult = UpdateSession.CreateUpdateSearcher();
UpdateSearchResult.Online = true;
ISearchResult SearchResults = UpdateSearchResult.Search("IsInstalled=1 AND IsPresent=1");
第二个选项是从下面提到的注册表项中读取信息
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall