如何在C#桌面应用程序中获取BIOS信息 [英] how to get bios information in c# desktop application

查看:319
本文介绍了如何在C#桌面应用程序中获取BIOS信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

请任何人告诉我如何在C#桌面应用程序中获取BIOS编号,硬盘编号,主板编号

hey guys

pls any one tell me to how to get bios no, hard disk no, mother board no in the c# desktop application

推荐答案

您可以尝试使用WMI,如下所示:
You might try using WMI, as follows:
using Microsoft.Win32;

ManagementObjectSearcher searcher = 
    new ManagementObjectSearcher(@"\\.\root\cimv2",
                                 "SELECT * FROM Win32_BIOS"));

foreach (var _object in searcher.Get())
{
    if (_object != null)
    {
        try
        {
            string object_name = "?";
            
            if (_object["Name"] != null)
            {
                object_name = _object["Name"].ToString();
            }
            else if (_object["Caption"] != null)
            {
                object_name = _object["Caption"].ToString();
            }
            else if (_object["Description"] != null)
            {
                object_name = _object["Description"].ToString();
            }
            
            foreach (var property in _object.Properties)
            {
                string property_name  = property.Name;

                if ((property.Value != null) &&
                    (!property_name.Contains("CreationClassName")))
                {
                    string property_value;
                    
                    if (!(property.Value is Array))
                    {
                        property_value = property.Value.ToString();
                    }
                    else
                    {
                        StringBuilder _property_value = new StringBuilder();
                        
                        Array _property_array = property.Value as Array;
                        
                        int count = 0;
                        
                        foreach (var entry in _property_array)
                        {
                            if (count > 0) _property_value.Append(",\r\n");
                            _property_value.Append(entry.ToString());
                            count++;
                        }

                        property_value = _property_value.ToString();
                    }
                }
            }
        }
        
        catch (ManagementException exception)
        {
            System.Diagnostics.Trace.WriteLine(exception.ToString());
        }
    }
}

此逻辑显示如何枚举WMI中有关BIOS的大多数信息.

This logic shows how to enumerate most of the information available in WMI about the BIOS.


Google是您的朋友:很好,经常拜访他.与在这里发布问题相比,他可以更快地回答问题.

使用 从问题中复制的搜索字符串 进行的简单查询发现了很多例子:
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A simple query using a search string copied from your question found loads of exampoles:
http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=bios+no%2C+hard+disk+no%2C+mother+board+no+in+the+c%23[^]

Please try to do at least basic research yourself in future, so as not to waste your time or ours.


这篇关于如何在C#桌面应用程序中获取BIOS信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆