用WMI查询电脑上硬盘的信息
使用wmi只要添加System.Managent这个dll
关于Win32_DiskDrive MSDN
项目->引用->添加引用->System.Managent
然后WQL:
Select * From Win32_DiskDrive
示例
Size 是容量(Byte) =柱面x磁头x扇区x512B
DeviceID是驱动器号
Model是关于生产厂商的一些信息
Partition是分区个数
using System;
using System.Management;
namespace test
{
class Program
{
static void Main(string[] args)
{
SelectQuery query = new SelectQuery("Select * From Win32_DiskDrive");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementBaseObject disk in searcher.Get())
{
Console.WriteLine(disk["Size"] + "\nPartitions:" + disk["Partitions"] + "\nName:" + disk["Name"]+ "\nPartitions:" + disk["DeviceID"] +"\n" + disk["Model"]);
}
Console.ReadLine();
}
}
}