title: C# WUApiLib: Failing to Install Updates with 0x80240024 Even Though Updates are Found
body: <p>I have followed instructions found on <a href="http://www.nullskull.com/a/1592/install-windows-updates-using-c--wuapi.aspx" rel="nofollow noreferrer">this site</a>, which was found when I researched <a href="https://stackoverflow.com/questions/26260393/c-sharp-wuapilib-download-and-install-asynchronously">Stack Overflow and found this question</a>. However, I can't seem to figure out why my code is hitting the catch block. I have a break at the IInstallationResult line, which the code hits but then goes to the catch, stating 0x80240024 (<a href="https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc720442(v=ws.10)?redirectedfrom=MSDN" rel="nofollow noreferrer">There are no updates</a>), even though there are certainly updates available and I list them in the text box.</p>
  <p>What am I missing here?</p>
  <pre><code>using System;
  using System.Windows.Forms;
  using WUApiLib;
  
  namespace TEST.DetectWindowsUpdate
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void GetUpdates(bool downloadUpdates, bool installUpdates)
          {
  
              UpdateSession uSession = new UpdateSession();
              IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
              UpdateCollection updatesToInstall = new UpdateCollection();
              UpdateDownloader downloader = uSession.CreateUpdateDownloader();
              IUpdateInstaller installer = uSession.CreateUpdateInstaller();
  
              uSearcher.Online = true;
  
              try
              {
                  ISearchResult sResult = uSearcher.Search(&quot;IsInstalled=0 And Type='Software'&quot;);
                  lblUpdateCount.Text = sResult.Updates.Count.ToString();
  
                  foreach (IUpdate update in sResult.Updates)
                  {
                      txtUpdatesList.AppendText(&quot;Title: &quot; + update.Title + Environment.NewLine);
                      txtUpdatesList.AppendText(&quot;IsInstalled: &quot; + update.IsInstalled.ToString() + Environment.NewLine);
                      txtUpdatesList.AppendText(&quot;Downloaded: &quot; + update.IsDownloaded.ToString() + Environment.NewLine);
                      txtUpdatesList.AppendText(&quot;IsMandatory: &quot; + update.IsMandatory.ToString() + Environment.NewLine);
  
                      txtUpdatesList.AppendText(Environment.NewLine);
  
                      if (downloadUpdates)
                      {
                          if (update.IsDownloaded == false)
                          {
                              do
                              {
                                  downloader.Updates.Add(update);
                                  downloader.Download();
                              }
                              while (update.IsDownloaded == false);
  
                              if (update.IsDownloaded == true)
                              {
                                  updatesToInstall.Add(update);
                              }
                          }
                          else
                          {
                              updatesToInstall.Add(update);
                          }
                      }
  
                      if (installUpdates)
                      {
                          installer.Updates = updatesToInstall;
  
                          IInstallationResult installationRes = installer.Install();
  
                          for (int i = 0; i &lt; updatesToInstall.Count; i++)
                          {
                              txtUpdatesList.AppendText(&quot;Installing &quot; + updatesToInstall[i].Title + &quot;...&quot;);
                              if (installationRes.GetUpdateResult(i).HResult == 0)
                              {
                                  txtUpdatesList.AppendText(&quot;INSTALL SUCCESS FOR &quot; + updatesToInstall[i].Title);
                              }
                              else
                              {
                                  txtUpdatesList.AppendText(&quot;INSTALL FAIL FOR &quot; + updatesToInstall[i].Title);
                              }
                          }
                      }
                  }
              }
              catch (Exception ex)
              {
                  Console.WriteLine(&quot;Error: &quot; + ex.Message + &quot;: &quot; + ex.HelpLink);
              }
          }
  
          private void btnGetUpdates_Click(object sender, EventArgs e)
          {
              
              base.OnLoad(e);
              txtUpdatesList.Clear();
              GetUpdates(false, false);
          }
  
          private void btnInstallUpdates_Click(object sender, EventArgs e)
          {
              base.OnLoad(e);
              txtUpdatesList.Clear();
              GetUpdates(true, true );
          }
      }
  }
  </code></pre>