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)
Any ideas? I have this,
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.
There may also be a tool called SerialPort; can I use it? If so, how do I use it?
Depending on how many files you have on the USB, what you can do is right-click on the files and click properties. There it should give you information about the file such as when it was created, last modified, and last accessed.
Removable devices including USB sticks don't store this information. You can perhaps find some specific products which implement an auditing / logging technology to remember the number / type of devices it has been plugged in, but if your specific device don't implement it then you can't.
Yes, it can be tracked. Its more common to just prevent users from using USB drives.
It is easy to check for removable devices. However, there's no guarantee that it is a 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:
DriveInfo
class (msdn documentation)DriveType
enumeration (msdn documentation)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With