WMI: Querying a specific instance of a class
See the question and my original answer on StackOverflowYou can use SQL for WMI WHERE clause queries, something like this:
var searcher = new ManagementObjectSearcher(
@"ROOT\StandardCimv2\embedded",
@"SELECT * FROM UWF_Servicing WHERE CurrentSession = FALSE");
foreach (ManagementObject obj in searcher.Get())
{
... etc ...
}
But you can also use the object's properties (values types will map to standard .NET's types), like this:
var searcher = new ManagementObjectSearcher(
@"ROOT\StandardCimv2\embedded",
@"SELECT * FROM UWF_Servicing");
foreach (ManagementObject obj in searcher.Get())
{
var currentSession = obj.GetPropertyValue("CurrentSession");
if (false.Equals(currentSession))
{
... etc ...
}
}