C#获取当前系统信息的类

///<summary>

/// Class designed to give information
/// about the current system
/// </summary>
public static classEnvironment
{
#regionPublic Static Properties
/// <summary>
/// Name of the machine running the app
/// </summary>
public static stringMachineName
{
get{ returnSystem.Environment.MachineName;}
}

/// <summary>
/// Gets the user name that the app is running under
/// </summary>
public static stringUserName
{
get{ returnSystem.Environment.UserName;}
}

/// <summary>
/// Name of the domain that the app is running under
/// </summary>
public static stringDomainName
{
get{ returnSystem.Environment.UserDomainName;}
}

/// <summary>
/// Name of the OS running
/// </summary>
public static stringOSName
{
get{ returnSystem.Environment.OSVersion.Platform. ToString();}
}

/// <summary>
/// Version information about the OS running
/// </summary>
public static stringOSVersion
{
get{ returnSystem.Environment.OSVersion.Version. ToString();}
}

/// <summary>
/// The service pack running on the OS
/// </summary>
public static stringOSServicePack
{
get{ returnSystem.Environment.OSVersion.ServicePack;}
}

/// <summary>
/// Full name, includes service pack, version, etc.
/// </summary>
public static stringOSFullName
{
get{ returnSystem.Environment.OSVersion.VersionString;}
}

/// <summary>
/// Gets the current stack trace information
/// </summary>
public static stringStackTrace
{
get{ returnSystem.Environment.StackTrace;}
}

/// <summary>
/// Returns the number of processors on the machine
/// </summary>
public static intNumberOfProcessors
{
get{ returnSystem.Environment.ProcessorCount;}
}

/// <summary>
/// The total amount of memory the GC believes is used
/// by the app in bytes
/// </summary>
public static longTotalMemoryUsed
{
get{ returnGC. GetTotalMemory( false);}
}

/// <summary>
/// The total amount of memory that is available in bytes
/// </summary>
public static longTotalMemory
{
get
{
longReturnValue = 0;
ObjectQuery TempQuery = new ObjectQuery( "SELECT * FROM Win32_LogicalMemoryConfiguration");
using(ManagementObjectSearcher Searcher = new ManagementObjectSearcher(TempQuery))
{
foreach(ManagementObject TempObject inSearcher. Get())
{
ReturnValue = long. Parse(TempObject[ "TotalPhysicalMemory"]. ToString())* 1024;
}
}
returnReturnValue;
}
}
#endregion
}

你可能感兴趣的:(C#)