Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have found some examples about how to lock and unlock Usb devices on a Windows machine using HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor registry key.
All the examples i have been able to find are for a manager-like executable in which you disable or enable usb access by changing registry key before you do something.
But what i intend to do is writing a windows service that locks usb access completely at start-up and spots if a usb device is plugged then ask for a password and if the password is correct allow access. But here is my problem;
When you disable usb devices by changing registry key, all the plugged usb devices are still disabled and invisible to windows and vice-versa; if you disable usb access, all previously plugged devices are still accessable.
This issue my "plug, enter password, use" concept impossible.
Since i dont know much about Windows&Registry stuff, can anyone point me at the right direction where i can(if i can) make windows re-scan plugged usb devices for all usb ports or for a specified port so that it wont be necessary to unplug&replug usb devices after entering password or a way to disable a specified usb port/hub, not all of them. Any other suggestions are also greatly appreciated.
Thank you.
Posted

1 solution

Hi,

Disabling a specified usb port is not possible cause of USB is a bus system.
Rescanning devices are quite simple, there're many ways to achieve it, disconnect all or speciefied usb device by checking VID and PID of Device.

This link explains much better than I'm able to write now:
http://www.developerfusion.com/article/84338/making-usb-c-friendly/[^]

I would start trying this way (not yet tested) first:
1. Block all devices/access to usb at startup.
2. Detect if usb device has plugged in.
3. Check for right password.
4. If it's correct, enable device.
5. Check if device gets disconnected and block again.

Maybe you have to rescan it between some of this points.

Another good links (libraries):
A USB HID Component for C#[^]

http://sourceforge.net/projects/libusbdotnet/[^]

Hope that helps.

With Best Regards
 
Share this answer
 
v3
Comments
y_dev 6-Apr-12 9:36am    
Hi Björn;
Sorry, I havent been able to write for a while.
I made a carelessly assumption about port specific disabling, thinking a virtual os addressing could be possible but you are right afterall its universal serial bus. Sorry about that.
My true intention was not to use a large library in my software but before i was lost but now i can try doing it without library, studying that library or at least use that as a last resort.

Thank you very much.
Regards.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900