Reputation: 15
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 keep looping until the device is found?
Upvotes: 0
Views: 301
Reputation: 612894
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.
Upvotes: 3
Reputation: 108975
You could use WMI (from C++ this will mean using WMI's COM API): creation events for the Win32_LogicalDisk
class.
Upvotes: 0