C#中如何获取系统版本,内存大小,显卡类型,CPU型号啊,急需!!
C#中如何获取系统版本,内存大小,显卡类型,CPU型号啊,急需!!
------解决方案--------------------using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Runtime.InteropServices;
private static CPU_INFO CpuInfo;
private static MEMORY_INFO MemoryInfo;
/// <summary>
/// 静态构造函数
/// </summary>
static ServerInfo()
{
CpuInfo = new CPU_INFO();
GetSystemInfo(ref CpuInfo);
MemoryInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref MemoryInfo);
}
#region 服务器相关硬件信息
#region 定义API引用
/// <summary>
/// CPU信息
/// </summary>
/// <param name= "cpuinfo "> CPU_INFO </param>
[DllImport( "kernel32 ")]
public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
/// <summary>
/// 内存信息
/// </summary>
/// <param name= "meminfo "> </param>
[DllImport( "kernel32 ")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
#endregion
#region CPU相关
/// <summary>
/// 获取CPU数量
/// </summary>
public static string Count
{
get { return CpuInfo.NumberOfProcessors.ToString(); }
}
/// <summary>
/// 获取CPU类型
/// </summary>
public static string Type
{
get { return CpuInfo.ProcessorType.ToString(); }
}
/// <summary>
/// 获取CPU等级
/// </summary>
public static string Level
{
get { return CpuInfo.ProcessorLevel.ToString(); }
}
/// <summary>
/// 获取CPUOemID
/// </summary>
public static string OemID
{
get { return CpuInfo.OemID.ToString(); }
}
/// <summary>
/// CPU页面大小
/// </summary>
public static string PageSize
{
get { return CpuInfo.PageSize.ToString(); }
}
#endregion
#region 内存相关
/// <summary>
/// 物理内存总大小
/// </summary>
public static string TotalPhys
{
get { return MemoryInfo.TotalPhys.ToString(); }
}
/// <summary>
/// 可用物理内存
/// </summary>
public static string AvailPhys
{
get { return MemoryInfo.AvailPhys.ToString(); }
}
/// <summary>
/// 交换页面总大小
/// </summary>
public static string TotalPageFile
{
get { return MemoryInfo.TotalPageFile.ToString(); }
}
/// <summary>
/// 可交换页面大小
/// </summary>
public static string AvailPageFile
{
get { return MemoryInfo.AvailPageFile.ToString(); }
}
/// <summary>
/// 虚拟内存总大小