Use the System.Management namespace and the Win32_Volume WMI class to do this. You can request an instance with DriveLetter from C: and get its FreeSpace property as follows:
ManagementPath path = new ManagementPath() { NamespacePath = @"root\cimv2", Server = "<REMOTE HOST OR IP>" }; ManagementScope scope = new ManagementScope(path); string condition = "DriveLetter = 'C:'"; string[] selectedProperties = new string[] { "FreeSpace" }; SelectQuery query = new SelectQuery("Win32_Volume", condition, selectedProperties); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query)) using (ManagementObjectCollection results = searcher.Get()) { ManagementObject volume = results.Cast<ManagementObject>().SingleOrDefault(); if (volume != null) { ulong freeSpace = (ulong) volume.GetPropertyValue("FreeSpace");
There is also a Capacity property that stores the total volume size.
Bacon source share