简体   繁体   English

如何枚举硬盘

[英]How to enumerate hard drives

I am writing a .net winforms application. 我正在编写.net winforms应用程序。 I want to be able to enumerate all of the hard drives on a system. 我希望能够枚举系统上的所有硬盘。

Furthermore I would love to be able to determine which of the drives is Fixed and Which is removable. 此外,我希望能够确定哪些驱动器是固定的,哪些是可移动的。

Finally, of the removable drives, I would love to be able to determine which of them is a flash (SSD or thumb) drive versus a standard hard drive. 最后,在可移动驱动器中,我希望能够确定它们中的哪一个是闪存(SSD或Thumb)驱动器还是标准硬盘驱动器。

For the first two points you want the following. 对于前两点,您需要以下内容。 I think you might have to switch to WMI to determine if a removable drive is solid state or hard drive based. 我认为您可能必须切换到WMI才能确定可移动驱动器是固态驱动器还是基于硬盘的驱动器。

foreach(DriveInfo info in DriveInfo.GetDrives())
{
   Console.WriteLine(info.Name + ":" + info.DriveType);
}

Produces a list of all the drives and their type from the DriveType Enum DriveType枚举生成所有驱动器及其类型的列表

You can use WMI to do that. 您可以使用WMI来做到这一点。 You'll need either Win32_DiskDrive or Win32_LogicalDisk . 您将需要Win32_DiskDriveWin32_LogicalDisk

DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
    if (drive.DriveType == DriveType.Fixed)
    {
        // Do something
    }
    else if (drive.DriveType == DriveType.Removable)
    {
        // Do something else
    }
}

But I don't know how you can determine whether it's Flash, SSD or hard drive... maybe with WMI 但是我不知道如何确定是Flash,SSD还是硬盘...也许使用WMI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM