System.Management.ManagementException:'无效查询'

编程入门 行业动态 更新时间:2024-10-28 06:33:37
本文介绍了System.Management.ManagementException:'无效查询' - 请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好

我是新来的,使用下面的脚本会出现错误 System.Management.ManagementException:'无效查询'

I new to this and using the script below comes up with an errorSystem.Management.ManagementException: 'Invalid query '

它说这个错误在foreach中(管理对象mo在mos.Get())

it says that this error is in foreach (ManagementObject mo in mos.Get())

但我不能使用System查看修复

but i cant see the fix

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Management; namespace NetPrimate_Provisioning_Tool_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnGet_Click(object sender, EventArgs e) { foreach (string cpu in GetComponents("WIN32_Processor", "Name")) { txtInfo.AppendText("CPU:" + cpu + Environment.NewLine); } foreach (string gpu in GetComponents("WIN32_VideoController", "Name")) { txtInfo.AppendText("GPU:" + gpu + Environment.NewLine); } foreach (string os in GetComponents("WIN32_OperatingSystem", "Caption")) { txtInfo.AppendText("OS:" + os); if(Environment.Is64BitOperatingSystem) { txtInfo.AppendText("64Bit" + Environment.NewLine); } else { txtInfo.AppendText("32Bit" + Environment.NewLine); } } string ram = GetComponents("WIN32_ComputerSystem", "TotalPhysicalMemory")[0]; double db_ram = Convert.ToDouble(ram) / 1073741824; int size = (int)Math.Ceiling(db_ram); txtInfo.AppendText("RAM:" + size.ToString() + "GB"); } public List<string> GetComponents(string hwclass, string syntax) { List<string> details = new List<string>(); ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT*FROM " + hwclass); foreach(ManagementObject mo in mos.Get()) { details.Add(mo[syntax].ToString()); } return details; } } }

推荐答案

您好ChrisDewey,

HiChrisDewey,

感谢您在此发帖。

对于你的问题,我测试你的代码。它是由查询字符串引起的。请更改 SELECT * FROM 来自以下代码。

For your question, I test your code. It caused by the query string. Please change SELECT * FROM from the following code.

更改

ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT*FROM " + hwclass);

ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM " + hwclass);

效果很好。

It works well.

最诚挚的问候,

Wendy

更多推荐

System.Management.ManagementException:'无效查询'

本文发布于:2023-11-08 22:21:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570606.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Management   System   ManagementException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!