0

i need to retrieve HDD related information like total number of partitions,in which driver OS is installed etc. programmatically in c#.any one here to help ?

3 Answers3

1

You can get available HDD related information from:

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

sample:

ManagementClass sampleClass= new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection SampleDrive= driveClass.GetInstances();
string Information="";
foreach (ManagementObject drives in SampleDrive) 
{ 

    foreach (PropertyData HDDproperty in drives .Properties)
    {
        Information +="HDDProperty: {0}, HDDValue: {1}", HDDproperty .Name, HDDproperty .Value);        
    }

}
4b0
  • 21,981
  • 30
  • 95
  • 142
1

For most information, you can use the DriveInfo class.

using System;
using System.IO;

class Info {
    public static void Main() {
        DriveInfo[] drives = DriveInfo.GetDrives();
        foreach (DriveInfo drive in drives) {
            //There are more attributes you can use.
            //Check the MSDN link for a complete example.
            Console.WriteLine(drive.Name);
            if (drive.IsReady) Console.WriteLine(drive.TotalSize);
        }
    }
}
Thilina H
  • 5,754
  • 6
  • 26
  • 56
0

WMI to rescue

You can use WMI queries to fetch information about system.

Example to fetch OS information related to OS

Other WMI samples

Rumit Parakhiya
  • 2,674
  • 3
  • 24
  • 33