/// <summary> /// Executes requests for default wmi data. Default data is: /// 1.) CSPRODUCT name and vendor /// 2.) OPERATING_SYSTEM caption and osarchitecture /// </summary> public void GetDefault() { if (!_defaultPopulated) { _defaultPopulated = true; KeyValuePair <Alias, String> [] defaultRequests = { new KeyValuePair <Alias, String>(WMI_ALIAS.CSPRODUCT, "name,vendor"), new KeyValuePair <Alias, String>(WMI_ALIAS.OPERATING_SYSTEM, "caption,osarchitecture") }; Parallel.ForEach(defaultRequests, request => { WMIProcessor wmi = new WMIProcessor(request.Key, request.Value, _isRemote); _properties.Add(wmi.Request, ParseWMIOutput(wmi.ExecuteRequest())); }); } }
/// <summary> /// Request additional wmi data using WMI_ALIAS and optional filter. /// </summary> /// <param name="request">WMI alias for type of data to request.</param> /// <param name="filter">Optional parameter. Filter results with a comma separated list of properties. Empty filter returns all data for alias.</param> public void GetData(Alias request, String filter = "") { if (request == null) { return; } if (!_defaultPopulated) { GetDefault(); } filter = DeduplicateFilter(request, filter); WMIProcessor wmi = new WMIProcessor(request, filter, _isRemote); if (_properties.ContainsKey(request)) { Parallel.ForEach(ParseWMIOutput(wmi.ExecuteRequest()), currentData => { // If property for alias already exists, update it. if (_properties[request].ContainsKey(currentData.Key)) { _properties[request][currentData.Key] = currentData.Value; } else { _properties[request].Add(currentData.Key, currentData.Value); } }); } else { _properties.Add(request, ParseWMIOutput(wmi.ExecuteRequest())); } }