WMI关闭磁盘

时间:2011-09-13 07:20:22

标签: c# windows wmi

我想关闭磁盘(WMI)。到目前为止,我有以下代码:

    ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2");
    ObjectQuery query = new ObjectQuery("SELECT * FROM CIM_DiskDrive");

    //create object searcher
    ManagementObjectSearcher searcher =
                            new ManagementObjectSearcher(scope, query);
    ManagementObjectCollection queryCollection = searcher.Get();

    //enumerate the collection.
    foreach (ManagementObject m in queryCollection)
    {
        Console.WriteLine("in set power state for: " + m.Path);
        ManagementOperationObserver obs = new ManagementOperationObserver();
        obs.Progress += new ProgressEventHandler(obs_Progress);
        obs.Completed += new CompletedEventHandler(obs_Completed);
        m.InvokeMethod(obs, "SetPowerState", new object[]{"7"});
    }

但是,磁盘活动仍在继续。任何有关正在发生的事情的想法都将受到赞赏。

1 个答案:

答案 0 :(得分:2)

WMI未实现SetPowerState:

http://msdn.microsoft.com/en-us/library/aa387254(v=VS.85).aspx

检查CompletedEventArgs.Status还将返回MethodNotImplemented,告诉我们是这种情况。如果要使用该方法,则必须实现自己的提供程序。