如何判断U盘插入?
怎么判断U盘或移动硬盘插入电脑?
怎么判断一个盘符是U盘或移动硬盘?
[解决办法]
查以前的帖子,我帖过代码。要不去delphi--FAQ里面找
另外不超blog里面都有
[解决办法]
遍历盘符,判断是否为移动的,
for(char i = 'A '; i <= 'Z '; i++)
{
AnsiString root = " ";
int nn;
root += i;
nn = GetDriveType(root.c_str());
switch(nn)
{
case 0:
ShowMessage( "无法检测到该驱动器 ");
break;
case 1:
ShowMessage( "根目录不存在 ");
break;
case DRIVE_REMOVABLE:
ShowMessage( "可移动盘 ");
break;
case DRIVE_FIXED:
ShowMessage( "固定盘 ");
break;
case DRIVE_REMOTE:
ShowMessage( "远程网络盘 ");
break;
case DRIVE_CDROM:
ShowMessage( "CD_ROM ");
break;
case DRIVE_RAMDISK:
ShowMessage( "RAM盘 ");
break;
default:
break;
}
}
[解决办法]
int check_connect_disk()
{
char Test_Connect_PHYSICALDRIVE[ ] = "\\\\.\\PHYSICALDRIVE0 ";
int j_how_many_disk_connect;
for(char i= '0 ';i < '9 ';i++)
{
Test_Connect_PHYSICALDRIVE[17] = i;
//奇怪,应该位置不是17,但输出\\\\.\\PHYSICALDRIVE1结果一般是\\.\PHYSICALDRIVE0
//正解,从\.\\PHYSICALDRIVE1开始
HANDLE hDevice = CreateFile(Test_Connect_PHYSICALDRIVE, // drive to open
0, // no access to the drive
FILE_SHARE_READ, // share mode
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes
//Test_Connect_PHYSICALDRIVE
if (hDevice != INVALID_HANDLE_VALUE) // cannot open the drive
{
//ShowMessage(Test_Connect_PHYSICALDRIVE);
//ComboBox1-> Items-> Add( "物理磁盘 "+IntToStr(i-48));
j_how_many_disk_connect=i-48+1;
}
}
return(j_how_many_disk_connect);//返回连接的磁盘的个数
}
刚写的,比较连接磁盘数目就行了