我想要创建的代码,设置速度底盘风扇,必须在windows 7上工作。
我尝试使用WMI代码创建者,但是我得到了错误Invalid object path。
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class CallWMIMethod
{
public static void Main()
{
try
{
ManagementObject classInstance =
new ManagementObject("root\\CIMV2",
"Win32_Fan.ReplaceKeyPropery='ReplaceKeyPropertyValue'",
null);
// Obtain in-parameters for the method
ManagementBaseObject inParams =
classInstance.GetMethodParameters("SetSpeed");
// Add the input parameters.
inParams["DesiredSpeed"] = 600;
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
classInstance.InvokeMethod("SetSpeed", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
}
catch(ManagementException err)
{
MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
}
}
}
}是否有任何可能参考案例风扇。有什么可以帮忙的吗?
发布于 2015-02-02 14:41:53
代码编译,因为它是有效的代码。它在运行时失败,因为您要求它做一些非法的事情。根据MSDN
、SetSpeed、、C、B、C、C、
既然如此,这一行将失败:
ManagementBaseObject inParams =
classInstance.GetMethodParameters("SetSpeed");如果SetSpeed没有实现(而不是简单地忽略),您将得到一个异常,试图检索与它相关的参数。移除Try/Catch以验证它发生在哪一行上。
制造商可能有一个实用程序,允许这样做,但似乎怀疑WMI能否工作。如果确实找到这样的工具,您可能需要计算bool属性VariableSpeed,以查看是否支持可变速度。
https://stackoverflow.com/questions/28279286
复制相似问题