需要
using System.Diagnostics;
using System.Management;
同样可以取得其他系统信息
//主板信息:
public static void GetBaseBoardInfo()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("Select * From Win32_BaseBoard");
foreach (ManagementObject mo in searcher.Get())
{
// mo["Manufacturer"],制造商,如“On-data”(昂达)
// mo["Product"],型号,如“KT400A-8235”
// mo["SerialNumber"],序列号
}
}
catch
{
}
}
//BIOS信息:
public static void GetBiosInfo()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("Select * From Win32_BIOS");
foreach (ManagementObject mo in searcher.Get())
{
// mo["Manufacturer"],制造商,如“Phoenix Technologies, LTD”
// mo["SerialNumber"],序列号
}
}
catch
{
}
}
//物理磁盘信息:
public static void GetPhysicalDiskInfo()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("Select * From Win32_DiskDrive");
foreach (ManagementObject mo in searcher.Get())
{
// mo["MediaType"],类型,如“Fixed hard disk media”
// mo["SizeBytes "],容量,如“80023749120”(字节)
}
}
catch
{
}
}
//网卡配置信息:
public static void GetNAConfigurationInfo()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("Select * From Win32_NetworkAdapterConfiguration");
foreach (ManagementObject mo in searcher.Get())
{
// mo["IPAddress"],IP地址
// mo["DefaultIPGateway"],默认网关
// mo["DNSServerSearchOrder"],DNS地址,如果有备用则会以数组形式返回
// mo["IPSubnet"],子网掩码
// mo["MACAddress"],MAC地址
}
}
catch
{
}
}
//CPU信息:
public static void GetProcessorInfo()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("Select * From Win32_Processor");
foreach (ManagementObject mo in searcher.Get())
{
// mo["L2CacheSize"],二级缓存,如“512”
// mo["Manufacturer"],制造商,如“AuthenticAMD”
// mo["MaxClockSpeed"],主频,如“1824”(1.824G)
// mo["ProcessorId"],ID,如“0383F9FF000006A0”
}
}
catch
{
}
}
//逻辑磁盘信息:
public static void GetLogicalDiskInfo()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("Select * From Win32_LogicalDisk");
foreach (ManagementObject mo in searcher.Get())
{
// mo["FileSystem"],文件系统,如“FAT32”
// mo["FreeSpace"],剩余空间,如“4554891264”(4G多)
// mo["Name"],卷标,如“C:”
// mo["Size"],大小,如“10476945408”(10G)
}
}
catch
{
}
}
参考http://msdn.microsoft.com/en-us/library/aa392727(v=VS.85).aspx