how to Fetch System Information in C#?

System.Windows.Forms namespace has SystemInformation class. The class has various static properties. To get information about the current system environment, use the class.

To determine the startup mode of the system, use BootMode property. The property can have values : Normal, FailSafe or FailSafeWithNetwork. All these values are defined in BootMode enumeration of System.Windows.Forms namespace.

using System;
using System.Windows.Forms;

//Add reference to System.Windows.Forms assembly.

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(SystemInformation.BootMode.ToString());
}
}
}

To access the computer name, use ComputerName property.

Console.WriteLine(SystemInformation.ComputeName);

To find out number of displays connected to machine, MonitorCount propery will help us.

Console.WriteLine(SystemInformation.MonitorCount.ToString());

Availability of mouse can be checked with the help of property MousePresent.

static void Main(string[] args)
{
if(SystemInformation.MousePresent)
Console.WriteLine("System has the mouse connected");
}

To check for network connection availability, use Network property.

if(SystemInformation.Network)
Console.WriteLine("System is connected to the network.");
There are lot many properties exposed by SystemInformation class.

No comments:

Post a Comment