I am using following code to get the path of the service…
string ServicePath = string.Format("Win32_Service.Name=\"{0}\"", "MyService");
var WMiObject = new ManagementObject(ServicePath);
string PathName = (string)WMiObject.GetPropertyValue("PathName");
Now if the service is not available then the call wmiObject.getPropertyValue(“PathName”)
will throw the ManagementException..
In my case i need to assign the HardCoded path if the service is not available..
How to achieve that??
Please guide…
You could probably use a try block around your WMiObject.GetPropertyValue call and assign the constant value in the catch block.