开发者

Can't get Win32_ComputerSystem - OEMStringArray in c#

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 o开发者_JAVA百科f this:

                ...
                string[] stringArray = mo5["OEMStringArray"] as String[];
                foreach (string myString in stringArray)
                {
                listBox2.Items.Add(stringArray);
                }

Any ideas ?

Thanks, elmatkos


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);
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜