检测计算机中是否有闪存驱动器 [英] Detect if the are Flash drives in a computer

查看:95
本文介绍了检测计算机中是否有闪存驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行检测计算机上是否为闪存驱动器的程序时遇到问题,请提供帮助!

Having problems with doing a program that will detect if the are flash drives on a computer, please help!!

推荐答案

例如,您可以列出可移动磁盘驱动器:

For example, you can list the removable drives:

using System.IO;

//...

DriveInfo[] drives = DriveInfo.GetDrives();

foreach (DriveInfo drive in drives) {
    if (drive.DriveType == DriveType.Removable)
         // do something...
}



或者,使用LINQ:



Or, with LINQ:

using System.IO;
using System.Linq;

DriveInfo[] removableDrives =
    DriveInfo.GetDrives().Where(drive => drive.DriveType == DriveType.Removable).ToArray();



据我所知,没有办法将闪存驱动器与其他可移动驱动器区分开.从某种意义上说,这并不是真正需要的.实际上,您只需要检查访问权限是否为只读,或者可以确保驱动器不是当前正在运行的OS的系统驱动器(因为您始终可以从可移动驱动器引导).

—SA



To best of my knowledge, there is no a way to tell the flash drive from other removable drive. In a way, this is not really needed. In practice, you only may need to check if the access is read-only or you may to make sure the drive is not the system drive of a currently running OS (because you can always boot from a removable drive).

—SA


如果您想在插入可移动驱动器时处理该事件,则情况将完全不同.这是使用USB可移动存储实现的方式:

http://stackoverflow.com/Questions/271238/how-do-i-detect-when-a-removable-disk-is-inserted-using-c [ ^ ].

不幸的是,这并没有穷尽所有可能性.例如,可移动存储设备可以集成在主板上,而SD/SDHC/SDXC驱动器通常就是这种情况.可以检测到此类事件,但不幸的是,目前我不知道该怎么办.

—SA
It would be a completely different story if you wanted to handle the event when the removable drive is inserted. This is the way you can do it with USB removable storage:

http://stackoverflow.com/questions/271238/how-do-i-detect-when-a-removable-disk-is-inserted-using-c[^].

Unfortunately, this does not exhaust all possibilities. For example, the removable storage could be motherboard-integrated, which is often the case with SD/SDHC/SDXC drives. Such events are detected, but unfortunately, I don''t know how to do it, at the moment.

—SA


这篇关于检测计算机中是否有闪存驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆