无法获取 Win32_ComputerSystem - C# 中的 OEMStringArray

发布于 2024-10-06 11:46:00 字数 1199 浏览 4 评论 0原文

尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泡沫很甜 2024-10-13 11:46:00

您给出的代码非常接近正确。将您的第一个示例与第三个示例中的 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);
        }
    }
}

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.

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);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文