开发者_开发百科Possible Duplicate:
How do I retrieve disk information in C#?
- I need a .net c# code example to detect each server's drive space.
- I also want step by step implementation instructions.
You can use the DriveInfo.GetDrives
method to retrieve an array of logical drives on a machine.
Example:
var nameAndFreeSpaceOfDrives = from drive in DriveInfo.GetDrives()
where drive.IsReady
select new { drive.Name, drive.TotalFreeSpace };
You also can use management objects to obtain free space:
using System.Management;
.........
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
MessageBox.Show(disk["FreeSpace"] + " bytes");
You also have to add reference to System.Management
assembly manualy
精彩评论