Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COSince you're filtering by `Name`, which a key property of the [Win32_Service class](http://msdn.microsoft.com/en-us/library/windows/desktop/aa394418.aspx), it would be faster to just access the instance directly without doing the search: `string path = "Win32_Service.Name=\"MyService\""; ManagementObject service = new ManagementObject(path); string pathName = (string) service.GetPropertyValue("PathName");` But I think the author is saying that it takes a long time for WMI to initialize, not that the query is taking too long to execute.
      singulars
    2. COYes, but using a query you're having to access the `Name` property of each `Win32_Service` instance. So, it's retrieving 25 properties of one instance vs. one property of all instances (on my 64-bit Windows 7 Professional laptop there are 188 services). In a quick test of 1,000 iterations of each method of retrieving the `PathName` property of a service, constructing a `ManagementObject` by path takes less than 10 seconds, whereas using a `ManagementObjectSearcher` takes about two minutes. Removing any `using` blocks and use of LINQ from the latter does get it down to about a minute.
      singulars
    3. CO@Bacon, I misunderstood your original comment about using the object path of the instance with the `ManagementObject` instead of `ManagementObjectSearcher`, your observation is quite correct, Also getting a `ManagementObject` directly is much better than get a `ManagementObjectSearcher` and enum each instance.
      singulars
 

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