How to detect if a USB or CD or any other drive is inserted using c++???

closed account (3hMz8vqX)
Hi all,
How to detect if a USB or CD or any other drive is inserted using c++???
I want to detect only drives no other hardware!
Thankyou everyone in advance!!! :)
closed account (3hMz8vqX)
Please, can anyone give me a simpler one???:)
Are you intimidated by the length? At least a third of that is commentary so that you know what each section of code is doing. It's meant to study from not to plug and go.
Here is an example for detecting the inserted USB
closed account (3hMz8vqX)
Hi all,
can I use GetDriveType() to detect USB. I could constantly run a loop of all drives A to Z and check if it is a Removable drive CD etc...
Any help on that?
can I use GetDriveType() to detect USB?
--> Yes.
GetDriveType() method discriminate the driver type (HDD, USB, DVD driver). However, when you plug new USB into computer, OS doesn't notify to your software
closed account (3hMz8vqX)
I said its run as a constant loop!
GetDriveType() is run inside a while loop ...
and my program is a background process:)
of course, you can do that.
But about performance, it's not good
closed account (3hMz8vqX)
Can you please tell me how to improve performance on my code?
Last edited on
By using RegisterDeviceNotificaton, of course.

Anyway, no offence, but you put so many questions and doing nothing on your own. What do you expect, an already written code for copy-pasting ?

Try to understand what the code works by writing it yourself. Does not work ? Write again !
Yes, exactly what I said before and few users got annoyed, although I hope people will listen to you, as you are a older member here and most likely a known one.

I bet you now, he will say - "I fixed my problem" or some BS like that. When in reality he did not. Anyway, not to be rude - but programmer must has his\her own strong research qualities. Copy Pasting will get him no where.
closed account (Dy7SLyTq)
is there a better way on linux than checking whats in the dev/proc folder?
closed account (3hMz8vqX)
The reason why I didnt use RegisterDeviceNotification is because Im developing a small scale application...
Thankyou all for your help:)
For Linux I think using libudev is the best choice from user mode:
As told you, he will try some BS to close this to avoid his Copy pasting to be shown in public.
Anyway modoran, you are a well polite guy lol. Unlike me.
closed account (3hMz8vqX)
Sorry, if you guys got annoyed,
but Im not a copy paster:)
closed account (Dy7SLyTq)
Then show us your source code
Topic archived. No new replies allowed.