Q:

WMI call takes too much time when system Starts/ReStarts

I want to get the path of the Windows Service,
var managementObjectSearcher = new ManagementObjectSearcher("Select * from Win32_Service where serviceName = MyService");

this code is written of the constructor of some other service...
everything works fine when system is UP and running but if i restart the system put the StopWatch class for this call and it shows that it shows that the service takes 35-45 seconds to start because of this call..
Any suggestions to improve the performance on system restart...

A:

The Windows32_Services class doesn't exist, so assuming which you are using the Win32_Service WMI class you can improve the performance only returning the properties which you want to use, in this case the PathName, so change your WQL sentence to 
SELECT PathName FROM Win32_Service Where Name='MyService'

UPDATE
The observation made for @Bacon is quite correct, since you know the name of thes service to retrieve, you can build the object path of the  Win32_Service which look like
Win32_Service.Name="ServiceName"

And then using the ManagementObject class you can retrieve the instance to the service in a fastest way.

