如何检测USB驱动器已插入? [英] How to detect a USB drive has been plugged in?

查看:220
本文介绍了如何检测USB驱动器已插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立检测是否一个​​USB(或两个或更多个)中都插入一个节目
(和所有内容复制到任何文件夹在硬盘上)

I want to build a program that detects if a usb (or two or more) are plugged in (and copy all contents to any folder on a hard disk)

任何想法?我有这个,

using System.Runtime.InteropServices;

但它不是简单的方法(我认为)。我想要的东西容易。

But it is not the easy way (that I believe). I want something easy.

我还有一个想法(如果(文件夹中),然后复制)的东西 - 但也有可能是一个问题了,并且我希望有一个好的解决方案。

I have another idea (if (folder exist) then copy) something -- but there may be a problem with that, and I want a good solution.

有也可以是称为的SerialPort工具;我可以用它?如果是这样,我怎么使用它?

There may also be a tool called SerialPort; can I use it? If so, how do I use it?

推荐答案

这是很容易检查移动设备,但它不保证它是一个USB设备:

It is easy to check for removable devices, however it doesn't guaranty that it is an USB device:

var drives = DriveInfo.GetDrives()
    .Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable);

这将返回当前访问的所有移动设备的列表。更多信息:

This will return a list of all removable devices that are currently accessible. More information:

这篇关于如何检测USB驱动器已插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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