Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
    Single Page App
    Bootstrap
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> C# >> Displaying computer system information using C#.
Displaying computer system information using C#.

Hi... In this blog I will teach you that how to display operating system and processor information by using c#.
Views: 7504     Comments: 0
by Awadhendra Tiwari on 5/19/2011

Operating system info and processor info in c#

Hi…

In this blog I will tell you that how to display operating system info and processor info by using c#. We can take help of WMI classes to display information of processor as well as to display information of operating system. There is another way to perform this task which is more efficient than WMI classes that is by using Registry editor. We know that Registry editor contains all information of system as well processor in their database. Then we can use registry editor to retrieve these values.

In this blog I will use concept, Registry as well as use WMI class. I will use Registry editor to display processor information and use WMI classes to display operating system information. Here is sample program which will complete out task..

Program to display operating system and processor info

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Management;   //This namespace is used to work with WMI classes. For using this namespace add reference of System.Management.dll .

using Microsoft.Win32;     //This namespace is used to work with Registry editor.

namespace OperatingSystemInfo1

{

    class TestProgram

    {

        static void Main(string[] args)

        {

            SystemInfo si = new SystemInfo();       //Create an object of SystemInfo class.

            si.getOperatingSystemInfo();            //Call get operating system info method which will display operating system information.

            si.getProcessorInfo();                  //Call get  processor info method which will display processor info.

            Console.ReadLine();                     //Wait for user to accept input key.

        }

    }

    public class SystemInfo

    {

        public void getOperatingSystemInfo()

        {

            Console.WriteLine("Displaying operating system info....\n");

            //Create an object of ManagementObjectSearcher class and pass query as parameter.

            ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_OperatingSystem");

            foreach (ManagementObject managementObject in mos.Get())

            {

                if (managementObject["Caption"] != null)

                {

                    Console.WriteLine("Operating System Name  :  " + managementObject["Caption"].ToString());   //Display operating system caption

                }

                if (managementObject["OSArchitecture"] != null)

                {

                    Console.WriteLine("Operating System Architecture  :  " + managementObject["OSArchitecture"].ToString());   //Display operating system architecture.

                }

                if (managementObject["CSDVersion"] != null)

                {

                    Console.WriteLine("Operating System Service Pack   :  " + managementObject["CSDVersion"].ToString());     //Display operating system version.

                }

            }

        }

        public void getProcessorInfo()

        {

            Console.WriteLine("\n\nDisplaying Processor Name....");

            RegistryKey processor_name = Registry.LocalMachine.OpenSubKey(@"Hardware\Description\System\CentralProcessor\0", RegistryKeyPermissionCheck.ReadSubTree);   //This registry entry contains entry for processor info.

            if (processor_name != null)

            {

                if (processor_name.GetValue("ProcessorNameString") != null)

                {

                    Console.WriteLine(processor_name.GetValue("ProcessorNameString"));   //Display processor ingo.

                }

            }

        }

    }

}

Output of following code snippet is as follows

Displaying operating system info....

Operating System Name  :  Microsoft Windows 7 Ultimate

Operating System Architecture  :  64-bit

Operating System Service Pack   :  Service Pack 1

Displaying Processor Name....

Intel(R) Core(TM)2 Duo CPU     E7500  @ 2.93GHz

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Awadhendra TiwariRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 4996
  
Copyright © 2009 - 2014MindStick. All Rights Reserved.