How do I get the environment / platform information?
Category: System, viewed: 392 time(s).
The System.Environment class allows us to get some information of the platform where we run our program. We can read information such as the machine name, number of processors it has, operation system version number, system directory, user domain name and current logged in user name.
using System;
namespace Kodecsharp.Example.System
{
class EnvironmentExample
{
public static void Main(string[] args)
{
//
// Gets the NetBIOS name of this local computer.
//
Console.WriteLine("Machine Name : " +
Environment.MachineName);
//
// Gets the number of processors the current machine has.
//
Console.WriteLine("Processor Count : " +
Environment.ProcessorCount);
//
// Gets the operating system information that contains the
// current platform identifier and the version number.
//
Console.WriteLine("OS Version : " +
Environment.OSVersion);
//
// Gets the fully qualified path to the system directory
//
Console.WriteLine("System Directory : " +
Environment.SystemDirectory);
//
// Gets the network domain name associated with the current
// user.
//
Console.WriteLine("User Domain Name : " +
Environment.UserDomainName);
//
// Gets user name of the current user login to the Windows
// operating system.
//
Console.WriteLine("User Name : " +
Environment.UserName);
Console.ReadLine();
}
}
}
This program outputs:
Machine Name : AURORA
Processor Count : 2
OS Version : Microsoft Windows NT 6.0.6001 Service Pack 1
System Directory : C:\Windows\system32
User Domain Name : AURORA
User Name : wsaryada
Download Hundreds of Complimentary Industry Resources
Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more;
all available at no cost to you. With more than 600 complimentary offers, you'll find
plenty of titles to suit your professional interests and needs.
Click Here and Sign up today!