尝试从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
答案 0 :(得分:1)
您给出的代码非常接近正确。将您的第一个样本与第三个样本中的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);
}
}
}