using System;
using System.Management;
namespace WmiListDisks
{
class Program
{
    static void Main( string[] args )
    {
        var path = @"\\.\root\cimv2"; 
        var query = @"Select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3"; 
        var worker = new ManagementObjectSearcher( path, query ); 
        var results = worker.Get(); 
       foreach( ManagementObject item in results )  
       {
           Console.WriteLine( "{0} {1} {2}", item[ "Name" ], item[ "Size" ], item[ "FreeSpace" ] );         
       }
    }
}
}
Advertisements