简体   繁体   English

在本地计算机上获取可用的物理驱

[英]Get available physical drives on local machine

I am trying to get all the physical drives available on local machine. 我试图在本地计算机上获得所有物理驱动器。 I tried to use GetLogicalDrives() but when i'm using this function it gets me also drives that physically not available on the machine, for example floppy drive A. Here is my code: 我尝试使用GetLogicalDrives()但是当我使用此功能时,它还GetLogicalDrives()我获得机器上不可用的驱动器,例如软盘驱动器A.这是我的代码:

void FindDrives()
{
    DWORD drives = GetLogicalDrives();
     for (int i=0; i<26; i++)
     {
        if( ( drives & ( 1 << i ) ) )
        {
           wchar_t driveName[] = { L'A' + i, L':', L'\\', L'\0'};
           std::wcout << driveName << std::endl;
        }
     }
}

How can I get only physically available drives? 我怎样才能获得物理上可用的驱动器?

Try using wmic 尝试使用wmic

wmic diskdrive list

for less info 少知情

wmic diskdrive list brief 

Alternatively in c use GetLogicalDrives() first to get all of the drives mapped in the system, and then GetDriveType() to find out which sort of drive each one is. 或者在c中首先使用GetLogicalDrives()来获取系统中映射的所有驱动器,然后使用GetDriveType()来找出每个驱动器的类型。 Then sort it out as you want to. 然后根据需要排序。

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

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