Hi - I've having trouble directly accessing the Win32_OperatingSystem management class that is exposed via WMI.
It is a singleton class, and I'm pretty certain "Win32_OperatingSystem=@" is the correct path syntax to get the instance of a singleton.
The call to InvokeMethod produces the exception listed at the bottom of the question, as does accessing the ClassPath property (commented line).
What am I doing wrong?
[I'm aware that I can use ManagementObjectSearcher/ObjectQuery to return a collection of Win32_OperatingSystem (which would contain only one), but since I know it is a singleton, I want to access it directly.]
ManagementScope cimv2 = InitScope(string.Format(@"\\{0}\root\cimv2", this.Name));
ManagementObject os = new ManagementObject(
cimv2,
new ManagementPath("Win32_OperatingSystem=@"),
new ObjectGetOptions());
//ManagementPath p = os.ClassPath;
os.InvokeMethod("Reboot", null);
System.Management.ManagementException was caught Message="Invalid object path " Source="System.Management" StackTrace: at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObject.Initialize(Boolean getObject) at System.Management.ManagementBaseObject.get_wbemObject() at System.Management.ManagementObject.get_ClassPath() at System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject& inParameters, IWbemClassObjectFreeThreaded& inParametersClass, IWbemClassObjectFreeThreaded& outParametersClass) at System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args)