试图从WMI获取OEMStringArray并将其用作Text,但是结果仍然是空的文本框。看起来ouput是string []。
像“ wmic computersystem get oemstringarray”这样的命令有效。
抱歉,我是新手程序员。
尝试过:
ManagementObjectSearcher mc7 = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
ManagementObjectCollection moc7 = mc7.Get();
if (moc7.Count != 0)
{
foreach (ManagementBaseObject mo7 in moc7)
{
textBox7.Text = mo7["OEMStringArray"].ToString();
}
}
并且:
ManagementClass mc3 = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc3 = mc3.GetInstances();
if (moc3.Count != 0)
{
foreach (ManagementObject mo3 in mc3.GetInstances())
{
textBox7.Text = mo3["OEMStringArray"].ToString();
}
}
其中一些:
...
string[] stringArray = mo5["OEMStringArray"] as String[];
foreach (string myString in stringArray)
{
listBox2.Items.Add(stringArray);
}
有任何想法吗 ?
谢谢,
Elmatkos
最佳答案
您提供的代码非常接近正确。将您的第一个样本与第三个样本中的ListBox
结合起来即可获得所需的内容。
ManagementObjectSearcher mc7 = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
ManagementObjectCollection moc7 = mc7.Get();
if (moc7.Count != 0)
{
foreach (ManagementBaseObject mo7 in moc7)
{
string[] data = mo7["OEMStringArray"] as string[];
if (data != null)
{
listBox2.Items.AddRange(data);
}
}
}
关于c# - 无法在C#中获得Win32_ComputerSystem-OEMStringArray,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4388556/