列出我的计算机上安装的物理驱动器
Listing physical drives installed on my computer
可能重复:
如何列出物理磁盘?
列出计算机上安装的物理驱动器的"最佳方式"(最快)C++是什么?有助推库可以做到这一点吗?
使用GetLogicalDriveStrings()
检索所有可用的逻辑驱动器。
#include <windows.h>
#include <stdio.h>
DWORD mydrives = 100;// buffer length
char lpBuffer[100];// buffer for drive string storage
int main()
{
DWORD test = GetLogicalDriveStrings( mydrives, lpBuffer);
printf("The logical drives of this machine are:nn");
for(int i = 0; i<100; i++) printf("%c", lpBuffer[i]);
printf("n");
return 0;
}
或使用GetLogicalDrives()
#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>
// initial value
TCHAR szDrive[ ] = _T(" A:");
int main()
{
DWORD uDriveMask = GetLogicalDrives();
printf("The bitmask of the logical drives in hex: %0Xn", uDriveMask);
printf("The bitmask of the logical drives in decimal: %dn", uDriveMask);
if(uDriveMask == 0)
printf("nGetLogicalDrives() failed with failure code: %dn", GetLastError());
else
{
printf("nThis machine has the following logical drives:n");
while(uDriveMask)
{// use the bitwise AND, 1–available, 0-not available
if(uDriveMask & 1)
printf("%sn",szDrive);
// increment...
++szDrive[1];
// shift the bitmask binary right
uDriveMask >>= 1;
}
printf("n ");
}
return 0;
}
一种可能性是使用WMI枚举Win32_DiskDrive的实例。
相关文章:
- 在Ubuntu 16.04上安装Cilk时出现问题
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- C++:如何在CLion IDE中安装Boost
- 安装opencv失败-粘贴CMakeError.log的内容
- 在cygwin中测试新的boost安装时出现cpp错误
- 有人安装"IITB Simplecpp in mac"吗?
- 我可以在 Arduino 的库文件夹之外安装库吗?
- Mingw-64 在构建和安装后不会编译 openCV 代码
- 为什么构建目录中新构建的共享库与安装目录中的副本具有不同的依赖项集?
- 在QTreeView中仅显示共享驱动器和文件夹
- 安装 libc++ 时出现问题
- 安装MinGW后C++编译器不起作用?
- 介子复制/安装头文件到输出目录并保持文件夹结构
- 无法安装 R 包 "nloptr"(Ubuntu 16.04 上的 R3.6.2) - C++编译器问题
- 如何在 Ubuntu 上安装 OpenCV for C/C++
- 如何查找Mac上是否真的存在已安装的驱动器
- 检测Linux和Mac OS X上安装的驱动器
- 列出我的计算机上安装的物理驱动器
- USB 上C++编译器(无需安装计算机(c 驱动器、PATH 等))的可移植 Eclipse CC++ 配置