using c# how can I extract information about the hard drives present on the local machine

后端 未结 4 372
夕颜
夕颜 2020-12-18 08:03

I\'m looking to get data such as Size/Capacity, Serial No, Model No, Heads Sectors, Manufacturer and possibly SMART data.

4条回答
  •  生来不讨喜
    2020-12-18 08:46

    You can use WMI Calls to access info about the hard disks.

    //Requires using System.Management; & System.Management.dll Reference

    ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\""); 
    disk.Get(); 
    Console.WriteLine("Logical Disk Size = " + disk["Size"] + " bytes"); 
    Console.WriteLine("Logical Disk FreeSpace = " + disk["FreeSpace"] + "bytes");
    

提交回复
热议问题