Recognize if removable drive was inserted
I have a piece of code to check the removable drives connected to the computer. But I have to check when the drive is available or inserted into the USB port.Should I write a while loop constantly checking for the drive with certain ID to become available? If I make it into a windows service, do I have to do the same i.e ke开发者_运维百科ep looping until the device is found?
Create a hidden window and use it to listen for WM_DEVICECHANGE messages.
Whatever you do, don't poll. That's horribly wasteful and inefficient.
You could use WMI (from C++ this will mean using WMI's COM API): creation events for the Win32_LogicalDisk
class.
精彩评论