I would like to repartition a USB drive using DiskPart from a C# application. This seems reasonably simple: I collect data about plugged disks using the Win32_DiskDrive class and then use DiskPart to run a script that will change the partitions. Critical point seems to be that of mapping the entry I select from Win32_DiskDrive to a disk number in DiskPart. For instance, this is the output of DiskPart:
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
* Disk 0 Online 100 GB 0 B
Disk 1 Online 14 GB 0 B
I need to select the disk by its number. But where do I get that number from data retrieved using Win32_DiskDrive? I guess the answer is using the "DeviceID" field, which returns this "\\.\PHYSICALDRIVE0". The index at the end seems to be the one I need to match the entry from Win32_DiskDrive to the related entry from DiskPart. Is this correct? Critical question is: is there any place in the official docs where this is stated without doubts? I will then format the device so I cannot do anything wrong here. Thanks.