Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Connecting:</p> <pre><code>try { rcOptions = new ConnectionOptions(); rcOptions.Authentication = AuthenticationLevel.Packet; rcOptions.Impersonation = ImpersonationLevel.Impersonate; rcOptions.EnablePrivileges = true; rcOptions.Username = servername + @"\" + username; rcOptions.Password = password; mScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", servername), rcOptions); mScope.Connect(); if (mScope.IsConnected == true) { MessageBox.Show("Connection Succeeded", "Alert"); } else { MessageBox.Show("Connection Failed", "Alert"); } if (mScope.IsConnected == true) { lblConnectionStateWarning.Text = "Connected"; } else { lblConnectionStateWarning.Text = "Disconnected"; } //I have a label that displays connectionstate, you can leave that out } catch (Exception ex) { MessageBox.Show(ex.Message); } </code></pre> <p>Getting query with method, loading into dictonary &amp; returning into listview</p> <pre><code>private void FindWMI(string servername, string classSelection, ConnectionOptions rcOptions, ListView listView) { try { var dct = new Dictionary&lt;string, string&gt;(); List&lt;ListViewItem&gt; itemsList = new List&lt;ListViewItem&gt;(); oQuery = new ObjectQuery("select * from " + classSelection); moSearcher = new ManagementObjectSearcher(mScope, oQuery); moCollection = moSearcher.Get(); Invoke(new MethodInvoker(() =&gt; { listView.Items.Clear(); })); foreach (ManagementObject mObject in moCollection) { if (mObject != null) { foreach (PropertyData propData in mObject.Properties) { if (propData.Value != null &amp;&amp; propData.Value.ToString() != "" &amp;&amp; propData.Name != null &amp;&amp; propData.Name != "") dct[propData.Name] = propData.Value.ToString(); //Don't forget this, when the result is an array, you want all the strings in that array.. if (propData.Value is Array) { dct[propData.Name] = ""; foreach (string stringArray in (string[])propData.Value) { dct[propData.Name] += stringArray + "\n"; } } } } } foreach (KeyValuePair&lt;string, string&gt; listItem in dct) { ListViewItem lstItem = new ListViewItem(listItem.Key); lstItem.SubItems.Add(listItem.Value); itemsList.Add(lstItem); } Invoke(new MethodInvoker(() =&gt; { listView.Items.AddRange(itemsList.ToArray()); })); } catch (Exception) { } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload