2013-09-27 44 views
0

我需要檢索硬盤相關的信息,如分區的總數,在哪個驅動程序操作系統安裝等編程在C#.anyany在這裏幫助?是否有任何C#類可用於檢索硬盤分區或其他信息的總數?

+0

可能重複(http://stackoverflow.com/questions/6575727/list-all-partitions-on-disk) –

+0

這可能會有幫助:如何我找回在C#中的磁盤信息](http://stackoverflow.com/q/412632/646543) – Michael0x2a

+0

檢查環境類的問題的某些部分的答案。 –

回答

1

你可以從可用硬盤的相關信息:

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

樣本:

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);   
    } 

} 
1

對於大多數信息,您還可以使用t他DriveInfo類。

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); 
     } 
    } 
} 
[列出所有分區在磁盤上]的
相關問題