Is there a way?
-
is there a way to get all the root paths of all the drives? like c:\ d:\ e:\ f:\ and so on..
WMI may help, but i dont know excatly how to do it. and there is probably a faster way, one of the guys here was using it to get the space used and space available on each drive on a system and remote server and it was kinda slow.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
is there a way to get all the root paths of all the drives? like c:\ d:\ e:\ f:\ and so on..
string[] drives = Environment.GetLogicalDrives();
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
is there a way to get all the root paths of all the drives? like c:\ d:\ e:\ f:\ and so on..
Hello Yes ! you can use WMI to get all connected drives
-
is there a way to get all the root paths of all the drives? like c:\ d:\ e:\ f:\ and so on..
Of course you can ... alot of ways to do so and WMI is one of them ... use the System.Management namespace to help you so ... as follows:
ArrayList list = new ArrayList();
using (ManagementObjectSearcher DiskSearch = new ManagementObjectSearcher(new SelectQuery("Select * from Win32_LogicalDisk")))
{
using (ManagementObjectCollection moDiskCollection = DiskSearch.Get())
{
foreach (ManagementObject mo in moDiskCollection)
{
list.Add(mo["Name"].ToString ());
MessageBox.Show(mo["Name"].ToString());
mo.Dispose();
}
}
}Dont forget to add a reference in your project to System.Management dll and you will get all the drives .. for more properties go to this link to get them (other than the Name property used here): http://msdn.microsoft.com/en-us/library/aa394173.aspx[^] Enjoy ! Note: If you found this answer useful please indicate that so other would know so.
Sincerely Samer Abu Rabie Software Engineer