Wednesday, February 6, 2008

c # code that shows all drives including network drives.

using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace RnDConsoleCSharp
{
class Program
{
static void Main(string[] args)
{
string driveLabel = null ;
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk ");

ManagementObjectCollection queryCollection = query.Get();



foreach (ManagementObject mo in queryCollection)
{


driveLabel = Convert.ToString(mo["VolumeName"] );


if (driveLabel.Length == 0)
{
driveLabel = Convert.ToString(mo["Description"]);
}


driveLabel += " (" + Convert.ToString(mo["Name"]) + ")";


Console.WriteLine(driveLabel);

}

Console.Read();
}
}
}

No comments:

About Me

He is working in an indian firm as a s/w engineer.During his work in the company he got many opportunities to deal with. He has experience on high-end techonologies like ASP, VB 6.0, MS.Net 2005, WMS, Python, Ajax, Ruby on Rails etc. He likes to work on client-server systems, remoting, web services, windows services etc. He loves to create utilities that makes his work easier and faster.