.net c# 获取当前电脑的硬盘详情信息,通过 ManagementClass 类初始化Win32_DiskDrive,然后获取Model,Size,SerialNumber,InterfaceType 等值
/// <summary>
/// 硬盘信息
/// </summary>
/// <returns></returns>
public static string GetDiskDriveInfo()
{
ManagementClass mangnmt = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection mcol = mangnmt.GetInstances();
StringBuilder sb = new StringBuilder();
uint i = 1;
foreach (ManagementObject mo in mcol)
{
var m = mo["Model"];
var size = Convert.ToInt64(mo["Size"]);
var sn = mo["SerialNumber"];
var it = mo["InterfaceType"];
sb.AppendLine($"序号{i}>>{m},{size / 1024 / 1024 / 1024}GB,序列号{sn},{it}");
sb.AppendLine();
i++;
}
return sb.ToString();
}
以下是运行效果: