Getting Operating System Information

This section provides a tutorial example on how to use execution environment class, System.Environment, to retrieve information about the OS (Operating System).

To test some of properties and methods supported on the System.Environment class, I wrote this tutorial example:

// EnvironmentInfo.cs
// Copyright (c) 2015,, All Rights Reserved.

using System;
class EnvironmentInfo {
   public static void Main() {
      String[] arguments = Environment.GetCommandLineArgs();
      Console.WriteLine("Command line arguments: {0}", 
         String.Join(", ", arguments));

      Console.WriteLine("Machine name: {0}", 

      OperatingSystem os = Environment.OSVersion;
      Console.WriteLine("Operating system: {0}", os.ToString());

      Console.WriteLine("# of CPU: {0}", Environment.ProcessorCount);

      Console.WriteLine("Uptime: {0} seconds", 

      String[] drives = Environment.GetLogicalDrives();
      Console.WriteLine("Logical drives: {0}", 
         String.Join(", ", drives));

      Console.WriteLine("Current directory: {0}",

      Console.WriteLine("Temporary directory: {0}",

Running this example on my Windows 7 machine, I got:

Command line arguments: EnvironmentInfo
Machine name: USDED-000716
Operating system: Microsoft Windows NT 6.1.7601 Service Pack 1
# of CPU: 4
Uptime: 25871 seconds
Logical drives: C:\, D:\, E:\
Current directory: C:\herong
Temporary directory: C:\Users\herong\AppData\Local\Temp

Last update: 2015.

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

 Data Type Features

 Floating-Point Data Types

 Passing Parameters to Methods

Execution Environment Class

 System.Environment - Execution Environment Class

Getting Operating System Information

 Getting CLR (Common Language Runtime) Information

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

 Compiling C# Source Code Files

 MSBuild - Microsoft Build Engine

 Memory Usages of Processes

 Multithreading in C#

 Async Feature from C# 5

 System.IO.FileInfo Class

 System.Diagnostics.FileVersionInfo Class

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Outdated Tutorials


 PDF Printing Version