일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Lotto
- Splunk
- dataframe
- mariadb
- synology
- LSTM
- GitHub
- imread
- pycharm
- E-P1
- ipad
- javascript
- SPL
- Numpy
- pandas
- index
- GT-S80
- 알고리즘
- CNN
- Button
- Series
- keras
- pip
- mean
- SciPy
- RNN
- 삼성소프트웨어멤버십
- Python
- DFS
- install
- Today
- Total
잠토의 잠망경
[Code Project]Detecting USB Drive Removal in a C# Program 본문
Introduction
This article describes my C# class called DriveDetector
which will allow your program to receive a notification when a removable drive (such as a flash drive) is inserted or removed. It also supports notifications about pending removal of such a device and cancelling this removal.
This is an updated version of the article first published in March 2007. The class is now easier to use — there is no need to specify a file to open on the flash drive or override WndProc
in your code. For details please see the What's new section at the bottom of this page.
Note that this class uses .NET Framework 2.0. It will not work with older versions. Also, it will only work in applications which have a window (not in console applications).
Recently, I wrote a program which allows the user to encrypt data on his/her flash drive. The program should decrypt and encrypt the data transparently when flash drive is inserted/removed. For this I needed to be informed when a flash drive is plugged in and when the user decides to remove it. I am quite new to C# so I started searching the internet for some solution. It didn't take me long to find out how to detect when a removable drive is inserted or removed, but I had a hard time trying to figure out how to get notified when the drive is about to be removed (when user clicks the remove hardware icon in system notification area). After making it all work I decided to put the code into a simple-to-use class and make it available to everyone. I hope you will find it useful. It's far from perfect but it works.
출처: http://www.codeproject.com/KB/system/DriveDetector.aspx