Click here to Skip to main content
12,634,982 members (28,855 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Windows USB registry
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 3-Apr-12 4:19am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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:[^]

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#[^][^]

Hope that helps.

With Best Regards
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 3 Apr 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100