Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Getting the list or number of physical drives(not logical drives)

Tags:

c#

winapi

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?

like image 919
dolgom Avatar asked Oct 05 '16 08:10

dolgom


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C full form?

Originally Answered: What is the full form of C ? C - Compiler . C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.


1 Answers

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.

like image 193
decPL Avatar answered Oct 10 '22 03:10

decPL