2014-09-09 2 views
2

개별 드라이브의 정보를 얻으려면 아래의 코드가 있지만 전체 HDD 정보를 원합니다 .I.E. 전체 크기 및 사용 가능한 공간 또는 사용 가능한 공간Cd에서 Total HardDrive를 사용할 수 있고 사용 된 cspace를 얻는 방법?

할당되지 않은 드라이브가있는 경우 드라이브 정보에서 해당 공간을 표시 할 수 없습니다.
예 : 500GB HDD가 있고이 파티션이 각각 200 개 (C & D) 인 경우이 함수는 C 및 D에 대한 정보 만 제공합니다. 사용되지 않거나 할당되지 않은 경우에도 할당되지 않은 공간 정보 (I.E. 기타 100GB)가 필요합니다.

+0

할당되지 않은 공간은 '드라이브'가 아니기 때문에 예상대로입니다. 나는 WMI가'Win32_DiskPartition'과 같은 객체에 파티션 정보를 줄 것이다. – Lloyd

+0

이것은 내 친구에게 도움이 될지도 모른다. :) http://stackoverflow.com/questions/7656857/how-to-get-unallocated-space-info-in- a-physical-disk –

답변

1

시도해보십시오.

public static void GetDiskspace() 
    { 
     ConnectionOptions options = new ConnectionOptions(); 
     ManagementScope scope = new ManagementScope("\\\\localhost\\root\\cimv2", 
     options); 
     scope.Connect(); 
     ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem"); 
     SelectQuery query1 = new SelectQuery("Select * from Win32_LogicalDisk"); 

     ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); 
     ManagementObjectCollection queryCollection = searcher.Get(); 
     ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(scope, query1); 
     ManagementObjectCollection queryCollection1 = searcher1.Get(); 

     foreach (ManagementObject m in queryCollection) 
     { 
      // Display the remote computer information 

      Console.WriteLine("Computer Name : {0}", m["csname"]); 
      Console.WriteLine("Windows Directory : {0}", m["WindowsDirectory"]); 
      Console.WriteLine("Operating System: {0}", m["Caption"]); 
      Console.WriteLine("Version: {0}", m["Version"]); 
      Console.WriteLine("Manufacturer : {0}", m["Manufacturer"]); 
      Console.WriteLine(); 
     } 

     foreach (ManagementObject mo in queryCollection1) 
     { 
      // Display Logical Disks information 

      Console.WriteLine("    Disk Name : {0}", mo["Name"]); 
      Console.WriteLine("    Disk Size : {0}", mo["Size"]); 
      Console.WriteLine("    FreeSpace : {0}", mo["FreeSpace"]); 
      Console.WriteLine("   Disk DeviceID : {0}", mo["DeviceID"]); 
      Console.WriteLine("  Disk VolumeName : {0}", mo["VolumeName"]); 
      Console.WriteLine("  Disk SystemName : {0}", mo["SystemName"]); 
      Console.WriteLine("Disk VolumeSerialNumber : {0}", mo["VolumeSerialNumber"]); 
      Console.WriteLine(); 
     } 
     string line; 
     line = Console.ReadLine(); 
    } 
+2

thnx 답장. 이것은 driveinfo 기능과 유사합니다. –