Script to check available diskspace in C#/.net
Here is a script to check free diskspace in C#/.net. It uses WMI logicaldisk object to retrieve information on the system drives.
.NET provides ManagementObject class to encapsulate the Windows WMI interface. Here is the sample code:
ManagementObject Disk = new ManagementObject("win32_logicaldisk.deviceid="c:"");
Disk.Get();
if (double.Parse(Disk["FreeSpace"].ToString()) / 1024 / 1024 / 1024 < 10)
// do something here
The above code gets a reference to the “C” drive and then checks if the free space is less than 10GB. The WMI API returns the space in bytes, hence, conversion to GB is required.
Related Posts
- How to detect the color of a person’s shirt
- Who is WHOIS?
- Changing domain IP address without modifying DNS
- Scripting form post in C# & .net
- Best Concise Linux System Administrator’s Guide (SAG)
- Getting your dynamic public IP in C# & .net
- My experience running PHP on IIS 7.5
- Fiddling with Fiddler
- Color Conversions
- Introduction to Face Detection and Face Recognition