using System;
using System.Collections.Generic;
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()) ##ERROR HERE##
{
details.Add(mo[syntax].ToString());
}
return details;
}
}
}嗨,我在我已经标记的线路(##ERROR,HERE##)上得到了无效的查询,但我似乎找不到修复的方法,有人能帮助我吗?此脚本应查看系统并获取系统信息。
发布于 2018-08-16 12:26:28
您的查询是错误的,您需要在标记之间插入空格:"SELECT * FROM " + hwclass,然后它将正常工作。
https://stackoverflow.com/questions/51866306
复制相似问题