Click here to Skip to main content
15,891,930 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends..
i want to retrieve my location's present from BIOS.
Thanks and Regards
Akkywadhwa
Posted

 
Share this answer
 
Comments
Akkywadhwa 30-Mar-12 11:24am    
I want to retrieve time from bios not from windows as windows time could be wrong but bios time can't be.
Try using WMI. Following is code for retrieving all the information provided by BIOS.

C#
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!
 
Share this answer
 
Comments
Akkywadhwa 29-Mar-12 17:07pm    
I am new to c# so could you,Please upload a demo project for me. I request you for this.
Regards,
Akkywdhwa

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900