Lenovo BIOS WMI - InvalidQuery

时间:2015-03-11 20:20:22

标签: c# wmi bios

我即将创建一个获取系统信息的工具。 只有Lenovo BIOS(WakeOnLAN)请求没有做我想要的。

调试器始终以"无效请求"停止。错误信息。

我尝试了以下内容......

ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\\\" + textBox1.Text + "\\root\\wmi", "SELECT * FROM Lenovo_BiosSetting WHERE InstanceName='ACPI\\PNP0C14\\1_0'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\\\" + textBox1.Text + "\\root\\wmi:Lenovo_BiosSetting.InstanceName='ACPI\\PNP0C14\\1_0'");

代码:

//LenovoWOL
        public string GetLenovoWOL()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\\\" + textBox1.Text + "\\root\\wmi:Lenovo_BiosSetting", "SELECT * FROM ACPI\\PNP0C14\\1_0");
            foreach (ManagementObject wmi in searcher.Get())
            {
                try
                {
                    return Environment.NewLine + wmi.GetPropertyValue("CurrentSetting").ToString();
                }
                catch { }
            }
            return "Unknown";
        }

仅当我删除I​​nstanceName部分时,代码才有效。

如果你有人告诉我,我做错了什么。 谢谢你的帮助

阿德里安

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。

这是我的代码。它不漂亮,但它有效。

ManagementPath path = new ManagementPath()
{
     NamespacePath = @"root\wmi",
     Server = textBox1.Text
};
     ManagementScope scope = new ManagementScope(path);
     SelectQuery Sq = new SelectQuery("Lenovo_BiosSetting");
     ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(scope, Sq);
     ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
     foreach (ManagementObject MO in osDetailsCollection)
     {
         if (MO["CurrentSetting"].ToString().Contains("WakeOnLAN"))
     {
         string[] arr = new string[3];
         ListViewItem itm;
         //add items to ListView
         arr[0] = "";
         arr[1] = "WakeOnLAN";
         arr[2] = MO["CurrentSetting"].ToString();
         itm = new ListViewItem(arr);
         listView200.Items.Add(itm);
    }
}

阿德里安