Check for a SPECIFIC device connected to USB port


Is it possible to programatically check when a specific device has been plugged into the USB port through VB6 or .net?? I wish to stop any Iphones being connected to a PC but need to allow other USB devices including pen drives. The only way I could think of is to scan through the conencted drives and then somehow track down the Iphone drive letter and then close the drive if detected?

Many thanks,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cant tell you how to code it, but I will tell you where to find it in the registry....


Plug one in, and search under this registry key for either "IPhone" or "Apple".....

Probably under something like this.....


Then you can do a reg search for these and delete the keys. Persopnally, I would create a dummy parent key, deny access to that subkey, so next time they try and plug it in it will fail to install.....

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can detect when (USB) devices are inserted using RegisterDeviceNotification() you need to specify the USB GUID {A5DCBF10-6530-11D2-901F-00C04FB951ED} in the DEV_BROADCAST_DEVICEINTERFACE structure  member dbcc_classguid. Then you will can recieve via callback or override window form WM_DEVICECHANGE.
The problem is how can you determine a usb disk from an iPhone? This I have never tried and I don't have such devices for testing but I think johnb6767 has the right idea but instead of the registry approach you can directly get this same information after registering for USB device changes. The information should be populated into the  DEV_BROADCAST_DEVICEINTERFACE under the member dbcc_name.
Then the other problem is how do you stop a user form using the device?... I have one idea for this which is the following...You must use DeviceIoControl() and lock the volume using FSCTL_LOCK_VOLUME then you need dismount the volume using FSCTL_DISMOUNT_VOLUME next ensure there is no media removal locks by using IOCTL_STORAGE_MEDIA_REMOVAL after that you can finally use IOCTL_STORAGE_EJECT_MEDIA to disable the drive.
You will also need administrative rights most likely on Vista and later because of the change in the way windows grants permission to volume handles on Vista and later which isn't the same for XP.
wildarmsdaveAuthor Commented:
Thanks for your help guys. I'll look into this in more detail when I have time but you have given me a good starting point.. I found the perfect thing on the CodeProject website but as its in C++ it is of no use to me. This shows the insertion and removal of a device and the option to disable it wich would be perfect.

There is also the link below which detects when an IPod is connected so I should be ble to modify this for an IPhone
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.