コード例 #1
0
 private void WMIPropsReceived(object sender, Common.Telnet.DataReceivedEventArgs e)
 {
     Dispatcher.Invoke(() =>
     {
         WMIProperties.Clear();
         WMIObjects.Clear();
         data = e.Content.Data as WMIObjectCollection;
         if (data.Namespace != SelectedNamespace || data.Class != SelectedClass)
         {
             return;
         }
         foreach (WMIPropertyCollection props in data)
         {
             WMIObjects.Add(props.Name);
         }
         if (WMIObjects.Count > 0)
         {
             SelectedWMIObject = WMIObjects[0];
         }
         RefreshGridViewColumns(lvw);
     });
 }
コード例 #2
0
        private async Task <bool> CollectWMIClass()
        {
            if (string.IsNullOrEmpty(WMIClassName))
            {
                MessageBox.Show("There is no selected WMI Class", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return(false);
            }

            WMIProperties.Clear();

            #region Preparation

            Cursor cursor = Main.Cursor;
            Main.Cursor = Cursors.Wait;
            Thread.Sleep(100);

            Main.WMIClassComboBox.Focus();
            Main.WMIClassComboBox.IsDropDownOpen = false;

            ConnectionOptions options = new ConnectionOptions
            {
                Impersonation = System.Management.ImpersonationLevel.Impersonate
            };

            ManagementScope scope = new ManagementScope("\\\\.\\root\\cimv2", options);
            scope.Connect();

            //Query system for Operating System information
            ObjectQuery query = new ObjectQuery($"SELECT * FROM {WMIClassName}");

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

            ManagementObjectCollection queryCollection = searcher.Get();

            #endregion Preparation

            try
            {
                int collectionIndex = 0;
                foreach (ManagementObject managementObject in queryCollection)
                {
                    int propertyIndex = 0;
                    foreach (PropertyData propertyData in managementObject.Properties)
                    {
                        WMIProperties.Add(new WMIProperty(collectionIndex, propertyIndex, propertyData));
                        propertyIndex++;
                    }
                    collectionIndex++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}", "Exception error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Main.Cursor = cursor;
            }

            //Main.WMIPropertiesDataGrid.ItemsSource = WMIProperties;
            return(true);
        }