Click here to Skip to main content
13,558,063 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


20 bookmarked
Posted 8 Apr 2012
Licenced CPOL

A simple application for gathering system information

, 8 Apr 2012
Rate this:
Please Sign up or sign in to vote.
In this tip you will learn how to collect system information by using System.Environment and System.Management.

System Information

CPU Information

Local Drives Information


In this application, user system information has been collected by using two classes:

  1. System.Environment
  2. System.Managememnt

Using the Code

The main tab in this application has three items:

  1. System
  2. CPU
  3. Local drives

In the System tab, the System.Environment class has been used to gather information:

private string SystemInformation()
    StringBuilder StringBuilder1 = new StringBuilder(string.Empty);
        StringBuilder1.AppendFormat("Operation System:  {0}\n", Environment.OSVersion);
        if (Environment.Is64BitOperatingSystem)
            StringBuilder1.AppendFormat("\t\t  64 Bit Operating System\n");
            StringBuilder1.AppendFormat("\t\t  32 Bit Operating System\n");
        StringBuilder1.AppendFormat("SystemDirectory:  {0}\n", Environment.SystemDirectory);
        StringBuilder1.AppendFormat("ProcessorCount:  {0}\n", Environment.ProcessorCount);
        StringBuilder1.AppendFormat("UserDomainName:  {0}\n", Environment.UserDomainName);
        StringBuilder1.AppendFormat("UserName: {0}\n", Environment.UserName);
        foreach (System.IO.DriveInfo DriveInfo1 in System.IO.DriveInfo.GetDrives())
                StringBuilder1.AppendFormat("\t Drive: {0}\n\t\t VolumeLabel: " + 
                  "{1}\n\t\t DriveType: {2}\n\t\t DriveFormat: {3}\n\t\t " + 
                  "TotalSize: {4}\n\t\t AvailableFreeSpace: {5}\n",
                  DriveInfo1.Name, DriveInfo1.VolumeLabel, DriveInfo1.DriveType, 
                  DriveInfo1.DriveFormat, DriveInfo1.TotalSize, DriveInfo1.AvailableFreeSpace);
        StringBuilder1.AppendFormat("SystemPageSize:  {0}\n", Environment.SystemPageSize);
        StringBuilder1.AppendFormat("Version:  {0}", Environment.Version);
    return StringBuilder1.ToString();

In the CPU and Local drive tabs, the System.Management class has been used to gather information but before using this class, it has to be added to references. Add System.Management to references:

  1. Go to Solution Explorer.
  2. Right click on References and select Add Reference.
  3. Click on .NET tab.
  4. Select System.Management.
  5. Select the OK button.

Now we can use this class in the following function:

private string DeviceInformation(string stringIn)
    StringBuilder StringBuilder1 = new StringBuilder(string.Empty);
    ManagementClass ManagementClass1 = new ManagementClass(stringIn);
    //Create a ManagementObjectCollection to loop through
    ManagementObjectCollection ManagemenobjCol = ManagementClass1.GetInstances();
    //Get the properties in the class
    PropertyDataCollection properties = ManagementClass1.Properties;
    foreach (ManagementObject obj in ManagemenobjCol)
        foreach (PropertyData property in properties)
                StringBuilder1.AppendLine(property.Name + ":  " + 
                //Add codes to manage more informations
    return StringBuilder1.ToString();

Notice that this function has an input string which can be Win32_Processor or Win32_LogicalDisk. We use the first one for collecting information about CPU and the second one for local drives. Now in the Window_Loaded event, we call these functions:

//System Information
textBox1.Text = SystemInformation();
//CPU Information
textBox2.Text = DeviceInformation("Win32_Processor");
//Local Drives Information
textBox3.Text = DeviceInformation("Win32_LogicalDisk");

Points of Interest

In this tip, you learned how to collect system information by using System.environment and System.managememnt.


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


About the Author

Software Developer
Canada Canada


  • MCSD (Microsoft Certified Solutions Developer): App Builder - Charter Member
  • MCSD (Microsoft Certified Solutions Developer): Web Applications
  • MCSA (Microsoft Certified Solutions Associate): Universal Windows Platform
  • MCSA (Microsoft Certified Solutions Associate): Web Applications - Charter Member
  • MCP (Microsoft Certified Professional)
  • Microsoft Specialist: Programming in HTML5 with JavaScript and CSS3

  • PMI-ACP (PMI Agile Certified Practitioner)
  • PMI-PBA (PMI Professional in Business Analysis)
  • PMP (Project Management Professional)
  • CIW Advanced HTML5 & CSS3 Specialist
  • CIW Site Development Associate
  • PSM (Professional Scrum Master)
  • PSPO (Professional Scrum Product Owner)

Timeline of my career focus:

1994: Batch files in Microsoft Dos
1995: GW-Basic, Q Basic
1996: Assembly, C
1999: Pascal, C++
2000: Bachelor of Science Degree in Computer Software Engineering
2001: Borland Delphi, Microsoft SQL Server, HTML
2002: Visual Basic, C--, Ada, Lisp, Prolog, JavaScript
2003: C#, Java
2004:, Computer Networks
2005: Master of Science Degree in Computer Software Engineering
2006: Data Mining
2007: XML, XQuery, XSLT
2008: WPF
2009: Silverlight, Network Administration
2010: ASP.NET MVC, JQuery, CSS, Ajax, LINQ, Entity Framework
2011: VMware Visualization (vSphere, vCenter)
2012: Microsoft SharePoint, Microsoft System Center, Microsoft Visualization (Hyper-V), Microsoft Exchange Server, Microsoft Lync, Windows 8 App
2013: Cloud Computing (VMware and Microsoft Hyper-V),
2014: Agile, Scrum
2015: Project Management
2016: Security, Android Development
2017: Microsoft .Net Core
2018: Data Science, Virtual Reality

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
shelby6712-May-12 9:11
membershelby6712-May-12 9:11 
GeneralRe: My vote of 4 Pin
MehdiNaseri27-Jan-13 23:02
memberMehdiNaseri27-Jan-13 23:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180515.1 | Last Updated 8 Apr 2012
Article Copyright 2012 by MehdiNaseri
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid