Tam*_*man 18 .net c# windows list
我的计算机上安装的每个更新和修补程序的列表,来自Microsoft Windows Update或知识库.我需要KBxxxxxx形式的每个ID或类似的表示...
目前我有:
const string query = "SELECT HotFixID FROM Win32_QuickFixEngineering";
var search = new ManagementObjectSearcher(query);
var collection = search.Get();
foreach (ManagementObject quickFix in collection)
Console.WriteLine(quickFix["HotFixID"].ToString());
Run Code Online (Sandbox Code Playgroud)
但这似乎没有列出所有内容,它只列出了QFE.
我需要它在Windows XP,Vista和7上运行.
Tam*_*man 12
在进一步搜索我之前发现的内容之后.(是的,与VolkerK先建议的相同)
使用以下代码,我可以获得一个列表,我可以从中提取KB编号:
var updateSession = new UpdateSession();
var updateSearcher = updateSession.CreateUpdateSearcher();
var count = updateSearcher.GetTotalHistoryCount();
var history = updateSearcher.QueryHistory(0, count);
for (int i = 0; i < count; ++i)
Console.WriteLine(history[i].Title);
Run Code Online (Sandbox Code Playgroud)
您可以使用IUpdateSession3 :: QueryHistory方法.
返回条目的属性在http://msdn.microsoft.com/en-us/library/aa386400(VS.85).aspx中描述.
Set updateSearch = CreateObject("Microsoft.Update.Session").CreateUpdateSearcher
Set updateHistory = updateSearch.QueryHistory(1, updateSearch.GetTotalHistoryCount)
For Each updateEntry in updateHistory
Wscript.Echo "Title: " & updateEntry.Title
Wscript.Echo "application ID: " & updateEntry.ClientApplicationID
Wscript.Echo " --"
Next
编辑:另请参阅http://msdn.microsoft.com/en-us/library/aa387287%28VS.85%29.aspx