WMI - direct access to a singleton instance from Win32_OperatingSystem

I am having problems directly accessing the Win32_OperatingSystem management class that opens through WMI.

This is a singleton class, and I'm sure that "Win32_OperatingSystem = @" is the correct path syntax to get a singleton instance.

InvokeMethod calls the exception at the bottom of the question, as does access to the ClassPath property (comment line).

What am I doing wrong?

[I know that I can use ManagementObjectSearcher / ObjectQuery to return the Win32_OperatingSystem collection (which will contain only one), but since I know this 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 Message = " " = "System.Management" : System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) System.Management.ManagementObject.Initialize(Boolean getObject) System.Management.ManagementBaseObject.get_wbemObject() System.Management.ManagementObject.get_ClassPath() System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject & inParameters, IWbemClassObjectFreeThreaded & inParametersClass, IWbemClassObjectFreeThreaded & outParametersClass) System.Management.ManagementObject.InvokeMethod(String methodName, Object [] args)


.

Nick - , :)

Uros. , - MSDN. , WBEMTest this.


: "1 " " : 1" "Win32_OperatingSystem = @"

ManagementScope , , . WMI, .

+3
6

, . , , Vista. , - Windows XP. , , ""?

0

Win32_OperatingSystem - , , Singleton, ManagementObjectSearcher.Get() ManagementClass.GetInstances(), . Win32_OperatingSystem - , ,

ManagementObject OS = new ManagementObject(@"Win32_OperatingSystem.Name='OSname'")

OSName - :

"Microsoft Windows XP Professional | C:\WINDOWS |\Device\Harddisk0\Partition1"

ManagementObjectSearcher, , .

+2

,

using System;
using System.Management;

namespace WmiPlay
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ManagementScope cimv2 = new ManagementScope(@"\\.\root\cimv2");
                ManagementObject os = new ManagementObject(cimv2, new ManagementPath("Win32_OperatingSystem=@"), new ObjectGetOptions());
                Console.Out.WriteLine(os);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
        }
    }
}

, ? Visual Studio, Vista x64.

+2

100% , , , ManagementObjectSearcher? , .

+1

, , , , Primary = true. Win32_OperatingSystem , , , , , , , Primary, true.

+1

:

: "1 " " : 1" > "Win32_OperatingSystem = @"

, . , :

"Win32_WmiSetting = @"

, .

+1

Source: https://habr.com/ru/post/1696799/


All Articles