How do I get a list of installed updates and hotfixes?

后端 未结 5 1769
盖世英雄少女心
盖世英雄少女心 2020-11-30 05:16

A list of every update and hotfix that has been installed on my computer, coming from either Microsoft Windows Update or from the knowledge base. I need the ID of each in th

相关标签:
5条回答
  • 2020-11-30 05:29
            string ExtractString(string s)
        {
            // You should check for errors in real-world code, omitted for brevity
            try
            {
                var startTag = "(";
                int startIndex = s.IndexOf(startTag) + startTag.Length;
                int endIndex = s.IndexOf(")", startIndex);
                return s.Substring(startIndex, endIndex - startIndex);
            }
            catch
            {
                return ("CNVFL");
            }
        }
    

    Above is a simple extract string method I use to find that KB is in the security package like Tom Wijsman had mentioned and run his.

    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){
       //sets KB here!!
       string _splitstring = ExtractString(history[i].Title);
       Console.WriteLine(_splitstring);
    }
    

    this would get you the KB number like you're looking for I believe

    0 讨论(0)
  • 2020-11-30 05:31

    You can use IUpdateSession3::QueryHistory Method.
    The properties of the returned entries are described at 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

    edit: also take a look at http://msdn.microsoft.com/en-us/library/aa387287%28VS.85%29.aspx

    0 讨论(0)
  • 2020-11-30 05:31

    Just in case you just want the list of updates and don't care if you get it via code or a GUI, here is how to do it in Powershell:

    1. Open PowerShell (preferably "run as admin")
    2. Type "get-hotfix" and hit enter. That's it.

    Get hotfixes

    0 讨论(0)
  • 2020-11-30 05:42

    After some further search on what I've found earlier. (Yes, the same as VolkerK suggests first)

    1. Under VS2008 CMD in %SystemRoot%\System32\ run a command to get a managed dll:
      tlbimp.exe wuapi.dll /out=WUApiInterop.dll
    2. Add WUApiInterop.dll as a project reference so we see the functions.

    Using the following code I can get a list from which I can extract the KB numbers:

    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);
    
    0 讨论(0)
  • 2020-11-30 05:52
    const string querys = "SELECT HotFixID FROM Win32_QuickFixEngineering";
    var search = new ManagementObjectSearcher(querys);
    var collection = search.Get();
    
    foreach (ManagementObject quickfix in collection)
    {
        hotfix = quickfix["HotFixID"].ToString();
    }
    
    listBox1.Items.Add(hotfix);
    

    This will populate the listbox with currently installed Hotfixes or Updates

    If you want to list all history of updates and hotfixes to show then, the above example of Tom Wijsman as stated will work

    0 讨论(0)
提交回复
热议问题