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 ?
Asked
Active
Viewed 128 times
0
-
possible duplicate of [List All Partitions On Disk](http://stackoverflow.com/questions/6575727/list-all-partitions-on-disk) – Tim Schmelter Sep 27 '13 at 07:47
-
This may be helpful: [How to I retrieve disk information in C#](http://stackoverflow.com/q/412632/646543) – Michael0x2a Sep 27 '13 at 07:48
-
Check the `Environment` class for the answers on some parts of your question. – Andrei V Sep 27 '13 at 07:48
-
thanku guys :) i'll look upon above mentioned links – Himanshu Baunthiyal Sep 27 '13 at 07:52
3 Answers
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.

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