获取电脑硬件信息
[csharp][csharp]
//作者:Ming
[csharp]
[csharp]
using System;
using System.Collections;
using System.Management;
namespace HardWareInfos
{
public sealed class HardWareInfo
{
static CpuInfo cpu;
static MotherBoard motherBoard;
static BiosInfo bios;
static PhysicalDiskInfo physicalDisk;
const string PROCESSOR = "Select * From Win32_Processor";
const string PROCESSOR2 = "Win32_Processor";
const string BASEBOARD = "Select * From Win32_BaseBoard";
const string BASEBOARD2 = "Win32_BaseBoard";
const string BIOS = "Select * From Win32_BIOS";
const string BIOS2 = "Win32_BIOS";
const string DISKDRIVE = "Select * From Win32_DiskDrive";
const string DISKDRIVE2 = "Win32_DiskDrive";
static Hashtable Table = null;
static HardWareInfo()
{
Table = new Hashtable();
}
public static Hashtable GetAllInfos(Informations info)
{
ManagementClass mcls = new ManagementClass(info.ToString());
foreach (ManagementObject mo in mcls.GetInstances())
{
foreach (PropertyData pd in mo.Properties)
{
try
{
Table.Add(pd.Name, mo.Properties[pd.Name].Value.ToString());
}
catch { }
}
}
return Table;
}
public static CpuInfo GetCpuId()
{
ManagementObjectSearcher mos = new ManagementObjectSearcher(PROCESSOR);
foreach (ManagementObject mo in mos.Get())
{
try
{
cpu.L2CacheSize = mo.Properties["L2CacheSize"].Value.ToString();
cpu.Manufacturer = mo.Properties["Manufacturer"].Value.ToString();
cpu.MaxClockSpeed = mo.Properties["MaxClockSpeed"].Value.ToString();
cpu.ProcessorId = mo.Properties["ProcessorId"].Value.ToString();
}
catch { }
break;
}
return cpu;
}
public static CpuInfo GetCpuId2()
{
ManagementClass mcls = new ManagementClass(PROCESSOR2);
foreach (ManagementObject mo in mcls.GetInstances())
{
try
{
cpu.L2CacheSize = mo.Properties["L2CacheSize"].Value.ToString();
cpu.Manufacturer = mo.Properties["Manufacturer"].Value.ToString();
cpu.MaxClockSpeed = mo.Properties["MaxClockSpeed"].Value.ToString();
cpu.ProcessorId = mo.Properties["ProcessorId"].Value.ToString();
}
catch { }
break;
}
return cpu;&
补充:软件开发 , C# ,