Check for a SPECIFIC device connected to USB port

Hi,

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,

Dave.
wildarmsdaveAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
johnb6767Connect With a Mentor Commented:
Cant tell you how to code it, but I will tell you where to find it in the registry....

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum

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

Probably under something like this.....

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\Vid_0fca&Pid_0004

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.....
0
 
nffvrxqgrcfqvvcConnect With a Mentor Commented:
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.
0
 
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.

http://www.codeproject.com/KB/system/HwDetect.aspx

There is also the link below which detects when an IPod is connected so I should be ble to modify this for an IPhone

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=60373&lngWId=1
0
All Courses

From novice to tech pro — start learning today.