Tell me if the drive is a partition or a separate hard drive

I write my own file search (why, because I want / maybe not to search for an existing program). I can get all drives in C # using the DriveInfo.GetDrives () method. Ideally, I would like to run a search in parallel only on disks that are a separate disk, and for partitions located on the same disk, they start them sequentially. Thus, I will not force drives to constantly search, as GetDrives returns all partitions or removable media. I know what I can say if it's USB drives and a hard drive? How can I accomplish this, will there be DriveInfo or any other methodology that?

+4
source share
1 answer

This related question shows how to find out using WMI (found in System.Management ):

 var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition"); foreach (var queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("Win32_DiskPartition instance"); Console.WriteLine("Name:{0}", (string)queryObj["Name"]); Console.WriteLine("Index:{0}", (uint)queryObj["Index"]); Console.WriteLine("DiskIndex:{0}", (uint)queryObj["DiskIndex"]); Console.WriteLine("BootPartition:{0}", (bool)queryObj["BootPartition"]); } 
+3
source

Source: https://habr.com/ru/post/1394400/


All Articles