Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

hard-drive

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

like image 950
AndyM Avatar asked Oct 24 '08 10:10

AndyM


2 Answers

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");
like image 111
Eoin Campbell Avatar answered Oct 12 '22 01:10

Eoin Campbell


You should use the System.Management namespace:

System.Management.ManagementObjectSearcher ms =
    new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject mo in ms.Get())
{
    System.Console.Write(mo["Model");
}

For details on the members of the Win32_DiskDrive class, check out:

http://msdn.microsoft.com/en-us/library/aa394132(VS.85).aspx

like image 21
Tamas Czinege Avatar answered Oct 12 '22 02:10

Tamas Czinege