C# Tutorials - Herong's Tutorial Examples - v3.32, by Herong Yang
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) 2008 HerongYang.com. 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}",
Environment.MachineName);
OperatingSystem os = Environment.OSVersion;
Console.WriteLine("Operating system: {0}", os.ToString());
Console.WriteLine("# of CPU: {0}", Environment.ProcessorCount);
Console.WriteLine("Uptime: {0} seconds",
Environment.TickCount/1000);
String[] drives = Environment.GetLogicalDrives();
Console.WriteLine("Logical drives: {0}",
String.Join(", ", drives));
Console.WriteLine("Current directory: {0}",
Environment.CurrentDirectory);
Console.WriteLine("Temporary directory: {0}",
Environment.GetEnvironmentVariable("TEMP"));
}
}
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
Table of Contents
Logical Expressions and Conditional Statements
System.Environment - Execution Environment Class
►Getting Operating System Information
Getting CLR (Common Language Runtime) Information
Visual C# 2010 Express Edition
C# Compiler and Intermediate Language
Compiling C# Source Code Files
MSBuild - Microsoft Build Engine
System.Diagnostics.FileVersionInfo Class
WPF - Windows Presentation Foundation