friendsterTalk - Friendster Forum

friendsterTalk - Friendster Forum

Welcome guest! Please Login or Register.

#1  2008-11-11 17:31:35

creamownedz
 active server protocol
creamownedz's display avatar
» FriendsterTalker
PsychoCoder
Class-S
Location: Ftalk & MCTF
Registered: 2008-03-22
Posts: 115
Last visit: Yesterday
Reputation: 7

Read free space on network drives [C#]

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


Code:

/// <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;
}

...Giving of reputation are highly appreciating for me...
Computers don't make errors what they do they do on purpose
...computer is my expertise...
....an addicted coder....
....don't ripp all my tutorials....

Search Friendstertalk

Board footer

FriendsterTalk is not affiliated with Friendster.com
Copyright © 2002–2009 PunBB

[ 8 queries - 0.022 second ]

Pay Per Click Ads by pay per click advertising by Kontera

FriendsterTalk.com x

Welcome to FriendsterTalk! You'll need to login in order to fully use all the features and view all the sections of this site.

Please register if you're not yet a member. =)