title: C# WMI query to string
body: <p>I would like to output results from a WMI query to a textbox or label in C#.</p>
  <p>But I get a <code>System.FormatException</code>, when I try to put result into a <code>textbox.text</code>.</p>
  <p>Here is my code:</p>
  <pre><code>using System;
  using System.Windows.Forms;
  using System.Management;
  
  ManagementScope scope = new ManagementScope();
  
  scope = new ManagementScope(@&quot;\\localhost\root\CIMV2&quot;);
  scope.Connect();
  
  SelectQuery query = new SelectQuery(&quot;SELECT * FROM Win32_OperatingSystem&quot;);
  ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
              
  using (ManagementObjectCollection queryCollection = searcher.Get())
  {
      foreach (ManagementObject m in queryCollection)
      {
           //this line produces the System.FormatException:
           textBox.Text = string.Format(&quot;Computer Name: { 0}&quot;, m[&quot;csname&quot;]);
       }
  } 
  </code></pre>