从BIOS检索时间 [英] Retrieving time from bios

查看:97
本文介绍了从BIOS检索时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友..
我想从BIOS中检索我所在的位置.
谢谢与问候
Akkywadhwa

Hi friends..
i want to retrieve my location''s present from BIOS.
Thanks and Regards
Akkywadhwa

推荐答案

GIYF
如何使用c#获取BIOS日期和时间 [^ ]
GIYF
How i get the BIOS Date and Time using c#[^]


尝试使用WMI.以下是用于检索BIOS提供的所有信息的代码.

Try using WMI. Following is code for retrieving all the information provided by BIOS.

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



希望有帮助!



Hope this help!


这篇关于从BIOS检索时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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