I'm making a utility in C# for a filesystem that isn't supported by windows, which means that I can't just access the drive. I need a way to list all partitions on the hard disk and writing/formatting them.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
You can use the following approach to get the Volume or DriveLetter on which the partition of disk is mounted.
From the
Win32_DiskDrive
class you can get theDriveNumber
by querying propertyIndex
or extracting theDriveNumber
fromName
attribute. Then queryAntecedent
andDependent
fromWin32_LogicalDiskToPartition
. In theAntecedent
value you will get the Disk Number and the partition it is trying to map the Volume, after that extract theDriveLetter
such as "C:", "D:" etc from theDependent
property. So by using this logic you can get theLogicalDrives
mounted on particularHardDisk
. I'm using this logic in my component to get theLogicalDrive
names ("C:", "D:" etc) for particular hard drive on my system.To list disk partitions you can use WMI.