Hi,
i am new to Visual C#.
i am trying to develop a file searcher utility similar to that of Windows
own 'Search for files and folder' for desktop.
i want to know is there a method that can return all the valid hard
disk/partitions on a system, so i can have a option like 'Local harddrives'
in my program.
i have used 'Directory.GetLogicalDrives()' but it also returns floppy and CD
drives letters as well.
i faced the same result when i used 'WqlObjectQuery("select * from
Win32_LogicalDisk")'.i must mention i am new to WMI as well.
However i have succeeded in isolating the logical drives by checking
"DriveType" property of Management Objects returned by this query.
WqlObjectQuery objectQuery = new WqlObjectQuery("select * from
Win32_LogicalDisk");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
ManagementObjectCollection disks = searcher.Get();
foreach (ManagementObject disk in disks)
{
if(disk["DriveType"].ToString() == "3")
{
Console.WriteLine("Disk = " + disk["deviceid"]);
}
}
The query takes considerable time to show the results so i was wondering if
there is a better way of getting the same result or speeding up execution of
this particular query. I dont want to use any unmanaged DLL to solve this.
Thanks for any help/hints offered.