C++如何检测磁盘是否为USB
一、解决方案
1 检测磁盘属性
2 判断STORAGE_BUS_TYPE是否为BusTypeUsb,确定USB类型
二、技术
1 获取磁盘设备句柄,如C盘。
注意:C盘设备名为L"\\.\C:",不要写错。
2 检测磁盘属性
注意:操作控制码为IOCTL_STORAGE_QUERY_PROPERTY
三、实现
#include <Windows.h>
#include <WinIoCtl.h>
#include <string>
#include <iostream>
bool IsUSB(std::wstring disk_name);
void main(){
bool ret = IsUSB(L"I:");
if (ret){
std::cout