无法获取 Win32_ComputerSystem - C# 中的 OEMStringArray
尝试从 WMI 获取 OEMStringArray 并将其用作文本,但结果仍然是空文本框。看起来输出是 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);
}
有什么想法吗?
谢谢, 埃尔马特科斯
Trying to get OEMStringArray from WMI and use it as Text, but result is still empty textbox. Looks like ouput is string[].
Command like "wmic computersystem get oemstringarray" works.
Sorry, I'm newbie programmer.
Tried:
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();
}
}
And also:
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();
}
}
Some of this:
...
string[] stringArray = mo5["OEMStringArray"] as String[];
foreach (string myString in stringArray)
{
listBox2.Items.Add(stringArray);
}
Any ideas ?
Thanks,
elmatkos
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您给出的代码非常接近正确。将您的第一个示例与第三个示例中的
ListBox
结合起来以获得您想要的结果。Your code as given was so close to being correct. Combine your first sample with the
ListBox
in your third sample to get what you want.