
This is a snippet used to read the free space on all network drives attached to the system
Instructions: Need reference to System.Management Namespace to access the WMI. Call the method to populate a Hashtable with the network drive information
/// <summary>
/// Method for reading the free space on all network drives
/// attached to the current system
/// </summary>
/// <returns></returns>
public Hashtable ReadFreeSpaceOnNetworkDrives()
{
//create Hashtable instance to hold our info
Hashtable driveInfo = new Hashtable();
//query the win32_logicaldisk for type 4 (Network drive)
SelectQuery query = new SelectQuery("select name, FreeSpace from win32_logicaldisk where drivetype=4");
//execute the query using WMI
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
//loop through each drive found
foreach (ManagementObject drive in searcher.Get())
{
//add the name & freespace to our hashtable
driveInfo.Add("Drive", drive["name"]);
driveInfo.Add("Space", drive["FreeSpace"]);
}
return driveInfo;
}-Offline- |