摘要:[C#]抓取硬碟代號與USB代號
using System.Management;
private void GetHddAndUsbInfo()
{
StringBuilder sb = new StringBuilder();
ManagementClass devs = new ManagementClass(@"Win32_Diskdrive");
ManagementObjectCollection moc = devs.GetInstances();
foreach (ManagementObject mo in moc)
{
foreach (ManagementObject b in mo.GetRelated("Win32_DiskPartition"))
{
foreach (ManagementBaseObject c in b.GetRelated("Win32_LogicalDisk"))
{
sb.AppendLine("==========================================================");
sb.AppendLine("Name : " + c["Name"].ToString());
}
}
}
MessageBox.Show(sb.ToString());
}
Y2J's Life:http://kimenyeh.blogspot.tw/