5

I implemented the program to read and analyze physical disk bit-by-bit by accessing the path "\\.\PhysicalDrive0".

I want users to select the physical disk among the list of physical disks.

I know that I could read another physical disk if I change the last number of the path, but I do not know how to get the physical disk list or the number of physical disks.

How could I get physical disk number lists?

Which function do I have to use?

0

1 Answer 1

10

Use WMI, for example:

using System.Management; List<String> result; var query = new WqlObjectQuery("SELECT * FROM Win32_DiskDrive"); using (var searcher = new ManagementObjectSearcher(query)) { result = searcher.Get() .OfType<ManagementObject>() .Select(o => o.Properties["DeviceID"].Value.ToString()) .ToList(); } 

This gives you a list of device IDs of physical drives in the system.

Sign up to request clarification or add additional context in comments.

5 Comments

It outputs all same names of 4 hard disks.
I need the number of each physical disk.
I've updated my answer - though it was provided only as example code. Have a look at other properties available if that's still not what you're looking for.
If it works, mark his reply so that it can help others.
No, it does not work. On a PC with 2 system drives configured as RAID 1 and 8 data disks configured as RAID 10 this query returns 2 drives.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.